我制作一个连接到WebSocket的VB6应用程序,Handshaking和预留数据部分正在按需要工作,目前我正在通过Winsock将字符串发送回Websocket,/ p>
我引用这篇博客文章来处理websocket握手和事情VB6 + Winsock prepared websocket server
我试过这样的
Private Declare Sub CopyMemory _
Lib "kernel32" _
Alias "RtlMoveMemory" (Destination As Any, _
Source As Any, _
ByVal Length As Long)
______________________________________________________________________
Private Sub Form_Load()
Winsock1.LocalPort = 6701
Winsock1.Listen
End Sub
Private Sub cmdCommand1_Click()
Dim str As String
Dim BT() As Byte
str = StrConv(tbMsg.Text, vbUnicode)
If WinSock1.State = sckConnected Then
ReDim BT(Len(str) - 1)
CopyMemory BT(0), str, Len(str)
WinSock1.SendData StrConv(BT, vbUnicode)
End If
End Sub
表示该方法,我在浏览器中收到错误
WebSocket与' ws://127.0.0.1:6701 /'的连接失败:服务器不得屏蔽它发送给客户端的任何帧。
我也尝试过,
WinSock1.SendData StrToByte(tbMsg.Text, vbUnicode)
Public Function StrToByte(strInput As String) As Byte()
Dim lPntr As Long
Dim bTmp() As Byte
Dim bArray() As Byte
If Len(strInput) = 0 Then Exit Function
ReDim bTmp(LenB(strInput) - 1) 'Memory length
ReDim bArray(Len(strInput) - 1) 'String length
CopyMemory bTmp(0), ByVal StrPtr(strInput), LenB(strInput)
For lPntr = 0 To UBound(bArray)
If bTmp(lPntr * 2 + 1) > 0 Then
bArray(lPntr) = Asc(Mid$(strInput, lPntr + 1, 1))
Else
bArray(lPntr) = bTmp(lPntr * 2)
End If
Next lPntr
StrToByte = bArray
End Function
通过这种方法我从浏览器中收到错误
WebSocket与' ws://127.0.0.1:6701 /'的连接失败:一个或多个保留位开启:reserved1 = 1,reserved2 = 0,reserved3 = 1
我也尝试过,
Private Sub cmdCommand1_Click()
Dim abData() As Byte
Dim i As Long
Str = tbMsg.Text
' Convert string to bytes
abData = StrConv(Str, vbFromUnicode)
For i = 0 To UBound(abData)
Debug.Print Hex(abData(i)); "='" & Chr(abData(i)) & "'"
Next
If VoicePrintSocket.State = 7 Then VoicePrintSocket.SendData abData
End Sub
通过这种方法我从浏览器中收到错误
WebSocket与' ws://127.0.0.1:6701 /'的连接失败:框架标题无效