''''''''''Server code
Dim intMax As Integer
Private Sub Command2_Click()
Winsock2.SendData "(" & Format(Time, "HH:MM") & ") " & Winsock2.LocalHostName & " »»> " & Text1.Text
List1.AddItem "(" & Format(Time, "HH:MM") & ") " & Winsock2.LocalHostName & " »»> " & Text1.Text
Text1.Text = ""
Text1.SetFocus
End Sub
Private Sub Form_Load()
Me.Winsock1(0).LocalPort = GetSetting(App.EXEName, "Options", "Port", "6668")
Winsock1(0).Listen
List1.AddItem "(" & Format(Time, "HH:MM") & ") " & Winsock2.LocalHostName & " »»> " & Text1.Text
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Command2_Click
End If
End Sub
Private Sub Winsock1_Close(Index As Integer)
Winsock1(Index).SendData "Conexão Fechada para:" & Winsock1(Index).RemoteHostIP & " Em: " & Now
Winsock1(Index).Close
List1.AddItem "Conexão Fechada para:" & Winsock1(Index).RemoteHostIP & " Em: " & Now
End Sub
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
intMax = intMax + 1
Load Winsock1(intMax)
Winsock1(intMax).LocalPort = 0
Winsock1(intMax).Accept requestID
List1.AddItem "Conexão iniciada para: " & Winsock1(Index).RemoteHostIP & " Em: " & Now
End If
End Sub
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strIncoming As String, Result As String
Dim sString As String, MyArray() As String
Winsock1(Index).GetData strIncoming
List1.AddItem strIncoming
Winsock1(Index).SendData Result
End Sub
'''''Client Code
Private Sub Command1_Click()
If Winsock2.State <> sckClosed Then Winsock2.Close
Winsock2.RemotePort = Combo1.Text
Winsock2.RemoteHost = Combo2.Text
Winsock2.Connect
' Try and Connect to the Server
Do Until Winsock2.State = sckConnected
DoEvents: DoEvents: DoEvents: DoEvents
If Winsock2.State = sckError Then
MsgBox "There was a problem connecting to the Server!" & vbCrLf & "Please try again later!", vbOKOnly, "Connection Error"
Exit Sub
End If
Loop
Winsock2.SendData Now & " »»> " & Text1.Text
Command2.Enabled = True
Text1.Enabled = True
Command1.Enabled = False
End Sub
Private Sub Winsock2_ConnectionRequest(ByVal requestID As Long)
intMax = intMax + 1
Winsock1(intMax).LocalPort = 0
Winsock1(intMax).Accept requestID
List1.AddItem "Conexão iniciada para: " & Winsock1(Index).RemoteHostIP & " Em: " & Now
Winsock2.SendData "Conexão iniciada para: " & Winsock1(Index).RemoteHostIP & " Em: " & Now
Winsock2.RemotePort = Combo1.Text
Winsock2.RemoteHost = Winsock1(Index).RemoteHostIP
Winsock2.Connect
' Try and Connect to the Server
Do Until Winsock2.State = sckConnected
DoEvents: DoEvents: DoEvents: DoEvents
If Winsock2.State = sckError Then
MsgBox "There was a problem connecting to the Server!" & vbCrLf & "Please try again later!", vbOKOnly, "Connection Error"
Exit Sub
End If
Loop
Winsock2.SendData Now & " »»> " & Text1.Text
Command2.Enabled = True
Text1.Enabled = True
Command1.Enabled = False
End Sub
Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Dim strReply As String
Winsock2.GetData (strReply)
MsgBox strReply
End Sub