MsgBox "You need to type your username!", vbCritical, "Unable to complete"
Exit Sub
End If
If txtIP.Text = "" Then
MsgBox "IP-Address not valid!"
Exit Sub
End If
wsMain.RemoteHost = txtIP.Text
wsMain.Connect
Do Until wsMain.State = 7
' 0 is closed, 9 is error
If wsMain.State = 0 Or wsMain.State = 9 Then
MsgBox "Error in connecting!", vbCritical, "Winsock Error"
' there was an error, so let's leave
wsMain.Close
Exit Sub
End If
DoEvents 'don't freeze the system!
Loop
' "log-in":
wsMain.SendData "U" & Chr(1) & txtUserName.Text
txtUserName.Enabled = False
txtMessage.Enabled = True
Command1.Caption = "Disconnect"
Else
wsMain.Close
Command1.Caption = "Connect"
txtReceived = ""
End If
End Sub
Private Sub Form_Load()
Call Option1_Click
End Sub
Private Sub Option1_Click()
Option1.Value = True
Option2.Value = False
txtIP.BackColor = &H8000000B
txtIP.Text = wsMain.LocalIP
txtIP.Enabled = False
End Sub
Private Sub Option2_Click()
Option1.Value = False
Option2.Value = True
txtIP.BackColor = &H80000005
txtIP.Text = ""
txtIP.Enabled = True
End Sub
Private Sub txtCommand_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If wsMain.State = sckConnected Then
wsMain.SendData "r" & Chr(1) & txtCommand.Text
txtCommand.Text = ""
KeyAscii = 0
Else
MsgBox "Es existiert momentan keine Verbindung!"
txtMessage.Text = ""
End If
End If
End Sub
Private Sub txtMessage_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If wsMain.State = sckConnected Then
wsMain.SendData "t" & Chr(1) & txtMessage.Text
txtMessage.Text = ""
KeyAscii = 0
Else
MsgBox "Es existiert momentan keine Verbindung!"
txtMessage.Text = ""
End If
End If
End Sub
Private Sub wsMain_Close()
txtReceived.SelStart = Len(txtReceived.Text)
txtReceived.SelText = "Connection to Server lost" & vbCrLf
End Sub
Private Sub wsMain_DataArrival(ByVal bytesTotal As Long)
Dim Data As String, CtrlChar As String
wsMain.GetData Data
CtrlChar = Left(Data, 1) ' Let's get the first char
Data = Mid(Data, 3) ' Then cut it off
Select Case LCase(CtrlChar) ' Check what it is
Case "m" ' Do stuff depending on it
MsgBox Data, vbInformation, "Msg from server"
Case "c"
Me.Caption = "Client - " & Data
Case "r"
server_answer = Data
txtReceived.SelStart = Len(txtReceived.Text)
txtReceived.SelText = Data & vbCrLf
Case Else
txtReceived.SelStart = Len(txtReceived.Text)
txtReceived.SelText = Data & vbCrLf
End Select
End Sub
Private Sub wsMain_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)