Results 1 to 3 of 3

Thread: [RESOLVED] winsock dies

  1. #1

    Thread Starter
    Fanatic Member drivenbywhat's Avatar
    Join Date
    Jan 2007
    Location
    VA - USA
    Posts
    866

    Resolved [RESOLVED] winsock dies

    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:
    1. Option Explicit
    2.  
    3. Private Sub cmdconnect_Click()
    4.  
    5. Winsock.RemoteHost = txtIp.Text  ' this is the Ip of the server 127.0.0.1 loops back to your own computer
    6. Winsock.RemotePort = 15151  ' this is the port it must be the same as the server
    7. Winsock.Connect  ' connect!
    8.  
    9. End Sub
    10.  
    11. Private Sub cmdListen_Click()
    12.  
    13. Winsock.LocalPort = 15151 'open the port on the local machine try to use ports between 3000 and 50000
    14. Winsock.Listen ' start listening, simple!
    15.  
    16. End Sub
    17.  
    18. Private Sub Winsock_ConnectionRequest(ByVal requestID As Long)
    19.  
    20. Winsock.Close 'this resets our socket ready to accept the incoming connection
    21. Winsock.Accept requestID 'accept the connection!
    22.  
    23. End Sub
    24.  
    25. Private Sub winsock_DataArrival(ByVal bytesTotal As Long)
    26.  
    27. Dim incommingData As String 'this stores the data we receive
    28.  
    29. Winsock.GetData incommingData ' this stores the data in the variable we set above
    30.  
    31. ' now we will display it in the textbox
    32.  
    33. txtChat.Text = txtChat.Text & vbCrLf & incommingData
    34.  
    35. End Sub
    36.  
    37. Private Sub cmdSend_click()
    38.  
    39. Winsock.SendData txtMessage.Text ' sends the data in the textbox
    40. txtChat.Text = txtChat.Text & vbCrLf & txtMessage.Text
    41.  
    42. End Sub

    What could be causing this? Even the textChat.text won't update locally.
    [vb5 & starting to move to vb2008] I appreciate the help I get from everyone. Thank you.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] winsock dies

    If this thread is actually resolved, please post the resolution as it might help someone else experiencing a similar problem.

    Thanks.

  3. #3

    Thread Starter
    Fanatic Member drivenbywhat's Avatar
    Join Date
    Jan 2007
    Location
    VA - USA
    Posts
    866

    Re: [RESOLVED] winsock dies

    Actually, I'm a bit embarassed to say the solution. The code above works just fine. I was never getting any errors. It was just that I didn't see the text coming in. That was the problem. I didn't have scrollbars to true and I didn't make the focus come to the last line that came in. So after moving down with the down arrow, I noticed that the text was coming in.
    [vb5 & starting to move to vb2008] I appreciate the help I get from everyone. Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width