ick()
End
End Sub
Private Sub Form_Load()
textsend.Visible = False
textget.Visible = False
Winsockserver.LocalPort = 1001
Winsockserver.Listen
End Sub
Private Sub textsend_Change()
Winsockserver.SendData textsend.Text
End Sub
Private Sub Winsockserver_Close()
Winsockserver.Close
End
End Sub
Private Sub Winsockserver_ConnectionRequest(ByVal requestID As Long)
textsend.Visible = True
textget.Visible = True
If Winsockserver.State <> sckClosed Then Winsockserver.Close
Winsockserver.Accept requestID
End Sub
Private Sub Winsockserver_DataArrival(ByVal bytesTotal As Long)
Dim tmpstr As String
Winsockserver.GetData tmpstr
textget.Text = tmpstr
End Sub
客户机程序使用的控件如下:
(1)Command1:退出按钮;
(2)Command2:连接按钮;
(3)Winsockclient:客户Winsock;
(4)Text1:主机名文本框;
(5)Textsend:发送数据文本框;
(6)Textget:接收数据文本框; 客户机程序的界面如图所示。
客户机程序的源代码如下:
Private Sub Command1_Click()
End
End Sub
Private Sub Command2_Click()
Winsockclient.Connect
End Sub
Private Sub Form_Load()
textsend.Visible = False
textget.Visible = False
Winsockclient.RemotePort = 1001
Winsockclient.RemoteHost = "sccdsz"
End Sub
Private Sub Text1_Change()
Winsockclient.RemoteHost = Text1.Text
End Sub
Private Sub textsend_Change()
Winsockclient.SendData textsend.Text
End Sub
Private Sub Winsockclient_Close()
Winsockclient.Close
End
End Sub
Private Sub winsockclient_Connect()
textsend.Visible = True
textget.Visible = True
Command2.Visible = False
End Sub
Private Sub winsockclient_DataArrival(ByVal bytesTotal As Long)
Dim tmpstr As String
Winsockclient.GetData tmpstr
textget.Text = tmpstr
End Sub