Private Sub commadn1_Click()
SendMsg = Text2.Text
SockCL.SendData SendMsg
End Sub
Private Sub Command2_Click() '发送\
Dim SendMsg As String
SendMsg = Text2.Text
SockCL.SendData SendMsg
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text1.Locked = True
End Sub
Private Sub SockCL_ConnectionRequest(ByVal requestID As Long)
If SockCL.State <> sckClosed Then SockCL.State = sckClosed
SockCL.Accept requestID
Text1.Text = "服务器请求连接!"
SockCL.SendData "连接成功"
End Sub
Private Sub SockCl_DataArrival(ByVal bytesTotal As Long)
Dim DataStr As String
SockCL.GetData DataStr' 接收数据到文本框中
If Text1.Text = "" Then
Text1.Text = DataStr
Else
Text1.Text = Text1.Text & vbCrLf & DataStr
End If
End Sub
Private Sub Command3_Click() ' 退出数据
SockCL.Close
End
End Sub
' 发送完毕后回显
Private Sub SockCL_SendComplete()
If Text1.Text = "" Then
Text1.Text = "客户端: " & SendMsg
Else
Text1.Text = Text1.Text & vbCrLf & "客户端: " & SendMsg
End If
End Sub
Private Sub Command1_Click() ' 连接
SockCL.RemoteHost = "192.168.0.123"
' 指定服务器端口名
SockCL.RemotePort = 9999
' 连接到服务器
SockCL.Connect
End Sub
通信成功后的界面截图如上。本软件还有另外一段为用WINSOCK写的TCP服务器的部分。整个源代码及程序见波仕WF232L产品的光盘。(end)