Hi im trying to get a simple Visual Basic client server message system to work using Winsock...
currently the client program uses the following code:
############################################################
Private Sub btnone_Click()
Winsock1.Close
Winsock1.RemoteHost = "127.0.0.1"
Winsock1.RemotePort = 1000
Winsock1.Connect
Do Until Winsock1.State = sckConnected
DoEvents: DoEvents: DoEvents: DoEvents
If Winsock1.State = sckError Then
MsgBox "Problem connecting!"
Exit Sub
End If
Loop
Winsock1.SendData (txtmessage.Text)
Winsock1.Close
End Sub
Private Sub Form_Unload(Cancel As Integer)
Winsock1.Close
End Sub
############################################################
and the server uses the following code:
############################################################
Private Sub Form_Load()
Winsock1.Close
Winsock1.LocalPort = 1000
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strIncoming As String
Winsock1.GetData strIncoming
MsgBox strIncoming
End Sub
Private Sub Form_Unload(Cancel As Integer)
Winsock1.Close
End Sub
############################################################
So I start the client program type my message and press the button to send it, the program sits there for a while a then displays the error message 'problem connecting!' as to say no connection has been made. However if I do a 'netstat-a' in dos, while the client it sitting around, this is what happens:
TCP: ME:1000 ME.co.uk:3515 CLOSE_WAIT
TCP: ME:3515 ME.co.uk:1000 FIN_WAIT_2
Please help me to get my program to work!!!
cheers
currently the client program uses the following code:
############################################################
Private Sub btnone_Click()
Winsock1.Close
Winsock1.RemoteHost = "127.0.0.1"
Winsock1.RemotePort = 1000
Winsock1.Connect
Do Until Winsock1.State = sckConnected
DoEvents: DoEvents: DoEvents: DoEvents
If Winsock1.State = sckError Then
MsgBox "Problem connecting!"
Exit Sub
End If
Loop
Winsock1.SendData (txtmessage.Text)
Winsock1.Close
End Sub
Private Sub Form_Unload(Cancel As Integer)
Winsock1.Close
End Sub
############################################################
and the server uses the following code:
############################################################
Private Sub Form_Load()
Winsock1.Close
Winsock1.LocalPort = 1000
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strIncoming As String
Winsock1.GetData strIncoming
MsgBox strIncoming
End Sub
Private Sub Form_Unload(Cancel As Integer)
Winsock1.Close
End Sub
############################################################
So I start the client program type my message and press the button to send it, the program sits there for a while a then displays the error message 'problem connecting!' as to say no connection has been made. However if I do a 'netstat-a' in dos, while the client it sitting around, this is what happens:
TCP: ME:1000 ME.co.uk:3515 CLOSE_WAIT
TCP: ME:3515 ME.co.uk:1000 FIN_WAIT_2
Please help me to get my program to work!!!
cheers