将字符串从VB6 Winsock发送到WebSocket

将字符串从VB6 Winsock发送到WebSocket,websocket,vb6,winsock,Websocket,Vb6,Winsock,我正在制作一个连接到WebSocket的VB6应用程序,握手和保留数据部分按我的需要工作,目前我在通过Winsock将字符串发送回WebSocket时遇到了困难 我指的是这篇博客文章,是关于websocket握手之类的 我试过这样做 Private Declare Sub CopyMemory _ Lib "kernel32" _ Alias "RtlMoveMemory" (Destination As Any, _

我正在制作一个连接到WebSocket的VB6应用程序,握手和保留数据部分按我的需要工作,目前我在通过Winsock将字符串发送回WebSocket时遇到了困难

我指的是这篇博客文章,是关于websocket握手之类的

我试过这样做

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
从这个方法来看,我在浏览器中遇到了一个错误,比如

到“ws://127.0.0.1:6701/”的WebSocket连接失败:服务器不能屏蔽它发送给客户端的任何帧

我也试过

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
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
从这个方法中,我得到一个类似浏览器的错误

到“ws://127.0.0.1:6701/”的WebSocket连接失败:一个或多个保留位打开:reserved1=1、reserved2=0、reserved3=1

我也试过

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
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
从这个方法中,我得到一个类似浏览器的错误

到“ws://127.0.0.1:6701/”的WebSocket连接失败:帧头无效