VB分辨对方发过来的是消息还是别的什么东西
程序代码:
Private Sub Com_OK_Click() FindFreeSock Dim X On Error GoTo Err If Com_OK.Caption = "侦听" Then With Socket(SockIndex) '设置远程主机名 .RemoteHost = Trim(T_PCIP.Text) '设置远程端口号 .RemotePort = Trim(T_Prot.Text) '绑定本地端口号 .Bind Trim(20000) End With CenterPrint Pic_Connect, "正在侦听......" ListView1.ListItems(m + X).SubItems(N) = T_PCIP.Text ListView1.ListItems(m + X).SubItems(N + 1) = T_Prot.Text Else With Socket(SockIndex) '设置远程主机名 .RemoteHost = Trim(T_PCIP.Text) '设置远程端口号 .RemotePort = Trim(20000) '绑定本地端口号 .Bind Trim(T_Prot.Text) End With CenterPrint Pic_Connect, "正在连接......" zx = Socket(SockIndex) Timer1.Enabled = True End If Exit Sub Err: MsgBox Err.Description, 16, Err.Number End Sub
程序代码:
Private Sub Socket_DataArrival(index As Integer, ByVal bytesTotal As Long) Dim Data As Boolean Dim getdata Dim ComByte As Long, Temp As Long, J As Long Static DataByt() As Byte Static FileByt() As Byte Static Received As Long Const PACKSIZE = 8192 '65536 ReDim DataByt(bytesTotal) Socket(index).getdata getdata Dim u u = Time() If InStr(1, getdata, ":\") <> "" Then Data = True ElseIf getdata = "Message" Then Message = True Exit Sub ElseIf getdata = "StartChat" Then Message = True Exit Sub ElseIf Message = True Then If Text1.Text = "" Then Text1.Text = u & Chr(13) & Chr(10) & "对方说:" & getdata Else Text1.Text = Text1.Text & Chr(13) & Chr(10) & Chr(13) & Chr(10) & u & Chr(13) & Chr(10) & "对方说:" & Text2.Text End If ElseIf getdata = "PetName" Then PetName = True Exit Sub ElseIf PetName = True Then PetChatName = getdata