问题
I'm Making a VB6 application that connected to WebSocket , the Handshaking and reserving data part is working as i need and , currently i'm stucked at the Sending a string back to Websocket via Winsock,
i'm referring this blog post to work with websocket handshaking and things VB6 + Winsock prepared websocket server
I have tried like this
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
Form that method , i'm getting an error in browser like
WebSocket connection to 'ws://127.0.0.1:6701/' failed: A server must not mask any frames that it sends to the client.
And also I have tried,
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
From this method i'm getting an error from browser like
WebSocket connection to 'ws://127.0.0.1:6701/' failed: One or more reserved bits are on: reserved1 = 1, reserved2 = 0, reserved3 = 1
And also I have tried,
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
From this method i'm getting an error from browser like
WebSocket connection to 'ws://127.0.0.1:6701/' failed: Invalid frame header
来源:https://stackoverflow.com/questions/37537671/send-string-from-vb6-winsock-to-websockets