一个server端
-
- Private Sub Command1_Click()
-
- End
-
- End Sub
-
-
-
- Private Sub Command2_Click()
- Winsockserver.SendData Text4.Text + ":" + textsend.Text
-
-
- textget.Text = textget.Text + vbCrLf + Text4.Text + ":" + textsend.Text + " " + Str(Time)
- textsend.Text = ""
- End Sub
-
- Private Sub Form_Load()
- Command2.Visible = False
- textsend.Visible = False
- Text4.Visible = False
- textget.Visible = False
- Label1.Visible = False
- Winsockserver.LocalPort = 1001
-
- Winsockserver.Listen
-
-
- End Sub
-
-
-
- Private Sub textsend_Change()
-
- 'Winsockserver.SendData textsend.text
-
- End Sub
-
-
-
- Private Sub textsend_KeyPress(KeyAscii As Integer)
- 'If KeyAscii = 13 Then
- 'Winsockserver.SendData textsend.text
- 'textsend.text = ""
- If KeyAscii = 13 Then
- Winsockserver.SendData textsend.Text
- ' Text1.text = Text1.text + vbCrLf + Text4.text + ": " + Text2.text + " " + Str(Time)
- textsend.Text = ""
-
- End If
- End Sub
-
- Private Sub Timer1_Timer()
- If Text4.Text = "" Then Text4.Text = "no name"
- End Sub
-
- Private Sub Winsockserver_Close()
-
- Winsockserver.Close
-
- End
-
- End Sub
-
-
-
- Private Sub Winsockserver_ConnectionRequest(ByVal requestID As Long)
- Command2.Visible = True
- textsend.Visible = True
-
- textget.Visible = True
- Text4.Visible = True
- Label1.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 = textget + tmpstr + textsend
- textget.Text = textget.Text + vbCrLf + tmpstr + " " + Str(Time)
- End Sub
'(1)Command1:退出按钮;
'(2)textsend:发送数据文本框;
'(3)Winsockserver: 服务器Winsock;
'(4)textget :接收数据文本框。
一个client端
- Private Sub Command1_Click()
-
- End
-
- End Sub
-
-
-
- Private Sub Command2_Click()
- On Error Resume Next
- Winsockclient.RemoteHost = Text1.Text
- Winsockclient.Connect
-
- End Sub
-
-
-
- Private Sub Command3_Click()
- Winsockclient.SendData Text4.Text + ":" + textsend.Text
-
- textget.Text = textget.Text + vbCrLf + Text4.Text + ":" + textsend.Text + " " + Str(Time)
- textsend.Text = ""
- End Sub
-
- Private Sub Form_Load()
- Command3.Visible = False
- textsend.Visible = False
- Text4.Visible = False
- textget.Visible = False
- Label2.Visible = False
- Label3.Visible = False
- Command2.Enabled = True
- Winsockclient.RemoteHost = "192.168.1.211"
- Winsockclient.RemotePort = 1001
-
- Winsockclient.RemoteHost = "sccdsz"
-
- End Sub
-
-
-
- Private Sub Text1_Change()
- Command2.Enabled = True
- 'Winsockclient.RemoteHost = Text1.Text
-
- End Sub
-
-
-
- Private Sub textsend_Change()
-
- 'Winsockclient.SendData textsend.Text
-
- End Sub
-
-
-
- Private Sub textsend_KeyPress(KeyAscii As Integer)
- 'If KeyAscii = 13 Then
- 'Winsockclient.SendData textsend.Text
- 'textsend.Text = ""
- If KeyAscii = 13 Then
- Winsockclient.SendData Text4.Text + ":" + textsend.Text
- textsend.Text = ""
- 'End If
- End If
- End Sub
-
- Private Sub Timer1_Timer()
- On Error Resume Next
- Winsockclient.Connect
- Winsockclient.RemoteHost = Text1.Text
- End Sub
-
- Private Sub Winsockclient_Close()
-
- Winsockclient.Close
-
- End
-
- End Sub
-
-
-
- Private Sub winsockclient_Connect()
-
- textsend.Visible = True
-
- textget.Visible = True
- Label2.Visible = True
- Label3.Visible = True
- Text4.Visible = True
- Command2.Enabled = True
- Command2.Visible = True
- Command3.Visible = True
- End Sub
-
-
-
- Private Sub winsockclient_DataArrival(ByVal bytesTotal As Long)
-
- Dim tmpstr As String
-
- Winsockclient.GetData tmpstr
-
-
- textget.Text = textget.Text + vbCrLf + tmpstr + " " + Str(Time)
-
- End Sub
'(1)Command1:退出按钮;
'(2)Command2:连接按钮;
'(3)Winsockclient:客户Winsock;
'(4)Text1:主机名文本框;
'(5)Textsend:发送数据文本框;
'(6)Textget:接收数据文本框;