winsock with VB6

ghardy used Ask the Experts™
I use winsock in my vb6 apps to make connection to a server.  Once the connection is established and I want to send out data immediately, it fails.  Here is the code:

tcpClient.RemoteHost = ""
tcpClient.remotePort = remotePortNum
tcpClient.Connect ""
If tcpClient.State = sckConnected Then
   tcpClient.SendData "This is client"
   Dim w As String
   w = "There is a problem"
   MsgBox w, vbCritical, "Connection Error"
   Exit Sub
End If

I am sure the connection is ok but it just goes to the else statement 'connection error'
However, if I don't do the if then else here.  But have an extra button, cmdA, set in my application.  Once the cmdA is click and execute the same if then else within the event.  It works perfectly ok.  Any idea why?  The socket doesn't have enough wait time to send out signal?

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

you arent connected yet. Your code executes faster then your client can do a handshake with the server to set up the connection. Try monitoring your winsock_connection event instead...
Check this out, this will explain everything you need to know about winsock, Its not mine, but its where i learned a lot of it.
Naveen SwamyYash Infinite Solutions Private Limited


msy be ur server might not be running properly or running on a diff port

ghardy, any luck? Need more help etc?
Author of the Year 2009

Hi ghardy,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept billsecondii's comment(s) as an answer.

ghardy, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept THIS comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial