0
Iam使用SendMessage向客戶端發送數據。如果字節長度大於125,則該Sub不起作用。如果字節長度小於125則一切正常。例如字節長度是138腳本不工作 這裏是代碼;Websocket VB服務器大數據發送
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