Server code
Private Sub Command1_Click()
On Error Resume Next
If Winsock1.State <> 7 Then
MsgBox "can not connected client", vbCritical, "error"
Else
Winsock1.SendData "message|" & Text1.Text
End If
End Sub
Private Sub Form_Load()
Winsock1.Close
Winsock1.LocalPort = 1111
Winsock1.Listen
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim recieve As String
Dim vector() As String
Winsock1.GetData recieve
vector() = Split(recieve, "|")
If (vector(0) = "message") Then
'MsgBox vector(1)
Text2.Text = vector(1)
End If
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Winsock1.Close
Winsock1.Listen
End Sub
Clieint Code
Private Sub Command1_Click()
If Command1.Caption = "connect" Then
Command1.Caption = "disconnect"
Winsock1.Connect Text1.Text, 1111
Else
If Command1.Caption = "disconnect" Then
Command1.Caption = "connect"
Label1.Caption = "disconnect"
Winsock1.Close
End If
End If
End Sub
Private Sub Command2_Click()
On Error Resume Next
If Winsock1.State <> 7 Then
MsgBox "can not connected client", vbCritical, "error"
Else
Winsock1.SendData "message|" & Text2.Text
End If
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
End Sub
Private Sub Winsock1_Connect()
Label1.Caption = "connected"
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim recieve As String
Dim vector() As String
Winsock1.GetData recieve
vector() = Split(recieve, "|")
If (vector(0) = "message") Then
'MsgBox vector(1)
Text3.Text = vector(1)
End If
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Label1.Caption = "error"
Winsock1.Close
End Sub
Private Sub Command1_Click()
On Error Resume Next
If Winsock1.State <> 7 Then
MsgBox "can not connected client", vbCritical, "error"
Else
Winsock1.SendData "message|" & Text1.Text
End If
End Sub
Private Sub Form_Load()
Winsock1.Close
Winsock1.LocalPort = 1111
Winsock1.Listen
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim recieve As String
Dim vector() As String
Winsock1.GetData recieve
vector() = Split(recieve, "|")
If (vector(0) = "message") Then
'MsgBox vector(1)
Text2.Text = vector(1)
End If
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Winsock1.Close
Winsock1.Listen
End Sub
Clieint Code
Private Sub Command1_Click()
If Command1.Caption = "connect" Then
Command1.Caption = "disconnect"
Winsock1.Connect Text1.Text, 1111
Else
If Command1.Caption = "disconnect" Then
Command1.Caption = "connect"
Label1.Caption = "disconnect"
Winsock1.Close
End If
End If
End Sub
Private Sub Command2_Click()
On Error Resume Next
If Winsock1.State <> 7 Then
MsgBox "can not connected client", vbCritical, "error"
Else
Winsock1.SendData "message|" & Text2.Text
End If
End Sub
Private Sub Winsock1_Close()
Winsock1.Close
End Sub
Private Sub Winsock1_Connect()
Label1.Caption = "connected"
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim recieve As String
Dim vector() As String
Winsock1.GetData recieve
vector() = Split(recieve, "|")
If (vector(0) = "message") Then
'MsgBox vector(1)
Text3.Text = vector(1)
End If
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Label1.Caption = "error"
Winsock1.Close
End Sub