|
楼主 |
发表于 2022-11-23 15:39
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
‘-------------------------------------以下为问题代码
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function timeGetTime Lib "winmm.dll" () As Long '定义到模块
Dim WithEvents websock As VBToolsLib.websocket
Private Sub UserForm_Initialize()
Set websock = New VBToolsLib.websocket
hw& = FindWindow(vbNullString, "tsportliu")
Debug.Print hw
websock.setwindowhandle hw
websock.setHttpHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"
websock.Open "wss://5hangzhou.goeasy.io/socket.io/?EIO=3&transport=websocket&b64=1"
Savetime = timeGetTime '记下开始时的时间
While timeGetTime < Savetime + 1000 '循环等待
DoEvents '转让控制权,以便让操作系统处理其它的事件
Wend
websock.send ("Wq 你好")
Savetime = timeGetTime '记下开始时的时间
Dim ReadBuffer(1 To 1024) As Byte
While timeGetTime < Savetime + 3000 '循环等待
DoEvents '转让控制权,以便让操作系统处理其它的事件
Wend
Debug.Print websock.readyState
End Sub
Private Sub websock_onclose()
Debug.Print "bye"
End Sub
Private Sub websock_onerror(ByVal errmsg As String)
Debug.Print "error"
End Sub
Private Sub websock_onmessage(ByVal msg As String)
Debug.Print msg
End Sub
Private Sub websock_onopen()
Debug.Print "hello"
End Sub
|
|