用特殊字符作界定字符串,然后通过正则表达式将数据写入或者读取,这样可以方便客户端和服务器间通信 Dim MaxIndex As Integer Private Sub Form_Load() wskServer(0).Listen End Sub Private Sub wskServer_ConnectionRequest(Index As Integer,ByVal requestID As Long) MaxIndex = MaxIndex + 1 Load wskServer(MaxIndex) wskServer(MaxIndex).Accept requestID wskServer(MaxIndex).SendData SetData(0,"hello") End Sub Public Function SetData(ByVal TypeId As Integer,ByVal Value As String) SetData = "<T>" & TypeId & "</T><D>" & Value & "</D>" End Function Public Function GetData(ByVal s As String) Dim re As Object Set re = CreateObject("VBScript.RegExp") re.IgnoreCase = True re.Global = True re.Pattern = "<T>(.*?)</T><D>(.*?)</D>" Dim col As New Collection For Each obj In re.Execute(s) col.Add Array(obj.SubMatches(0),obj.SubMatches(1)) Next Set GetData = col End Function Private Sub wskServer_DataArrival(Index As Integer,ByVal bytesTotal As Long) Dim s As String wskServer(Index).GetData s Set col = GetData(s) For i = 1 To col.Count Text1.Text = Text1.Text & col(i)(1) & vbCrLf Next i End Sub