2014-06-14 4 views
0

클라이언트에 데이터를 보내기 위해 SendMessage를 사용합니다. 바이트 길이가 125보다 큰 경우이 Sub는 작동하지 않습니다. 바이트 길이가 125보다 작은 경우 모두 좋습니다. 예를 들어 바이트 길이는 138입니다. 스크립트가 작동하지 않습니다. 다음은 코드입니다.Websocket VB Server 대용량 데이터 전송

Sub SendMessage(sck As Socket, message As String) 
    Dim rawData = System.Text.Encoding.UTF8.GetBytes(message) 
    Dim frameCount = 0 
    Dim frame(10) As Byte 
    frame(0) = CByte(129) 
    Console.WriteLine("bukar:" & rawData.Length) 
    If rawData.Length <= 125 Then 
     frame(1) = CByte(rawData.Length + 1) 
     frameCount = 2 
    ElseIf rawData.Length >= 126 AndAlso rawData.Length <= 65535 Then 
     frame(1) = CByte(126) 
     Dim len = CByte(rawData.Length + 1) 
     frame(2) = CByte(((len >> 8) & CByte(255))) 
     frame(3) = CByte((len & CByte(255))) 
     frameCount = 4 
    Else 
     frame(1) = CByte(127) 
     Dim len = CByte(rawData.Length + 1) 
     frame(2) = CByte(((len >> 56) & CByte(255))) 
     frame(3) = CByte(((len >> 48) & CByte(255))) 
     frame(4) = CByte(((len >> 40) & CByte(255))) 
     frame(5) = CByte(((len >> 32) & CByte(255))) 
     frame(6) = CByte(((len >> 24) & CByte(255))) 
     frame(7) = CByte(((len >> 16) & CByte(255))) 
     frame(8) = CByte(((len >> 8) & CByte(255))) 
     frame(9) = CByte((len & CByte(255))) 
     frameCount = 10 
    End If 
    Dim bLength = frameCount + rawData.Length 
    ' Console.WriteLine(frameCount) 
    'Console.WriteLine(rawData.Length) 
    Dim reply(bLength) As Byte 

    Dim bLim = 0 
    For i = 0 To frameCount - 1 
     ' Console.WriteLine(bLim) 
     reply(bLim) = frame(i) 
     bLim += 1 
    Next 

    For i = 0 To rawData.Length - 1 
     ' Console.WriteLine(bLim) 
     reply(bLim) = rawData(i) 
     bLim += 1 
    Next 
    'For i = 0 To reply.Length - 1 
    'Console.WriteLine("Byte: " & reply(i)) 
    'Console.WriteLine("Char: " & CByte(reply(i))) 
    'Next 
    sck.Send(reply, reply.Length, 0) 
End Sub 

답변

0

VB에 대해 많이 알지는 못하지만 WebSockets에 대해 알고 있습니다.

0 - 129 
1 - 126 
2 - 0 
3 - 138 

확인 코드가 해당 헤더를 생성하는 경우 :

138 바이트의 전체 메시지 프레임 헤더는 4 바이트이어야한다.

WebSocket server connector for .NET/Mono을 개발했으며 GitHub의 소스 코드를 확인하면 문제가 해결 될 수도 있습니다. 물론 VB에서 라이브러리를 사용할 수도 있습니다.

건배.