Skip to content

2026-01-26-修复VB6保留字冲突

Winsock/cWinSock.cls

新增枚举

新增 WinSocketEventMaskEnum 枚举,用于同步方法的参数:

vb
Public Enum WinSocketEventMaskEnum
    wskSfdRead = 2 ^ 0
    wskSfdWrite = 2 ^ 1
    wskSfdOob = 2 ^ 2
    wskSfdAccept = 2 ^ 3
    wskSfdConnect = 2 ^ 4
    wskSfdClose = 2 ^ 5
    wskSfdAll = 2 ^ 6 - 1
    [_wskSfdResolve] = 2 ^ 15
    [_wskSfdForceRead] = 2 ^ 14
End Enum
  • cAsyncSocketUcsAsyncSocketEventMaskEnum 复制
  • 枚举成员前缀: ucsSfdwskSfd
  • 用于 SyncWaitForEvent 方法的 EventMask 参数

cAsyncSocket 已经通过条件编译 #If ImplSync Then 实现了完整的同步方法集:

  • SyncConnect - 同步连接,带超时
  • SyncReceiveText/SyncReceiveArray/SyncReceive - 同步接收
  • SyncSendText/SyncSendArray/SyncSend - 同步发送
  • SyncWaitForEvent - 等待指定事件
  • SyncCancelWait - 取消等待
  • SyncProcessMsgQueue - 处理消息队列

这些方法通过底层的 PeekMessage/DispatchMessage 和消息泵机制,不会阻塞UI消息循环。

现在 cWinsock 同时支持异步事件驱动模式和同步阻塞模式,开发者可以根据场景灵活选择使用。

vb
' 同步客户端示例
Dim WithEvents ws As New cWinsock

Sub TestSyncClient()
    ' 同步连接
    If ws.SyncConnect("example.com", 80, 5000) Then
        Debug.Print "连接成功!"

        ' 同步发送请求
        Dim sRequest As String
        sRequest = "GET / HTTP/1.1" & vbCrLf & vbCrLf
        If ws.SyncSendText(sRequest, 5000) Then
            Debug.Print "发送成功!"

            ' 同步接收响应
            Dim sResponse As String
            sResponse = ws.SyncReceiveText(100, 5000, , , wcpUtf8)
            Debug.Print "收到: " & sResponse
        End If
    End If

    ws.Close_
End Sub

VB6及其LOGO版权为微软公司所有