Hi. I am practicing winsock with a simple instant messenger sample. I thought I had it working but I had not tested enough to see that it was in fact not working properly. I can get the program to listen to a port or to connect to a remote port. This works fine. I can even send messages back and forth. However, after a total of two messages, winsock seems to die without error. It will no longer send the data between programs.
My test environment is as follows: two PCs in same subnet, in LAN. The program is set to listen to port 15151 if it is the server & set to send data to remote port 15151 if it's the client. IP address are 192.168.0.2 & 0.4. Layer 3 switch has firewall turned off. Windows Firewall is set to allow the program to make or listen for connection. Like I said, it works for the first two messages and then it no longer sends the data. Here is the code:
vb Code:
Option Explicit Private Sub cmdconnect_Click() Winsock.RemoteHost = txtIp.Text ' this is the Ip of the server 127.0.0.1 loops back to your own computer Winsock.RemotePort = 15151 ' this is the port it must be the same as the server Winsock.Connect ' connect! End Sub Private Sub cmdListen_Click() Winsock.LocalPort = 15151 'open the port on the local machine try to use ports between 3000 and 50000 Winsock.Listen ' start listening, simple! End Sub Private Sub Winsock_ConnectionRequest(ByVal requestID As Long) Winsock.Close 'this resets our socket ready to accept the incoming connection Winsock.Accept requestID 'accept the connection! End Sub Private Sub winsock_DataArrival(ByVal bytesTotal As Long) Dim incommingData As String 'this stores the data we receive Winsock.GetData incommingData ' this stores the data in the variable we set above ' now we will display it in the textbox txtChat.Text = txtChat.Text & vbCrLf & incommingData End Sub Private Sub cmdSend_click() Winsock.SendData txtMessage.Text ' sends the data in the textbox txtChat.Text = txtChat.Text & vbCrLf & txtMessage.Text End Sub
What could be causing this? Even the textChat.text won't update locally.





Reply With Quote