Link to home
Start Free TrialLog in
Avatar of ghardy
ghardy

asked on

winsock with VB6

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.Close
tcpClient.RemoteHost = "127.0.0.1"
tcpClient.remotePort = remotePortNum
tcpClient.Connect "127.0.0.1"
           
If tcpClient.State = sckConnected Then
   tcpClient.SendData "This is client"
Else
   Dim w As String
   w = "There is a problem"
   MsgBox w, vbCritical, "Connection Error"
   tcpClient.Close
   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?

Thanks.
Avatar of mccainz2
mccainz2

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...
ASKER CERTIFIED SOLUTION
Avatar of billsecondii
billsecondii

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ghardy, any luck? Need more help etc?
Avatar of DanRollins
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