I have the following code. It's a simple client/server chat. Can someone please tell me what errors to look for when using winsock and how to handle/avoid them. I know if I press the button to LISTEN or CONNECT when it's doing that stuff already, the program errors out.

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