winsock with VB6

ghardy
ghardy used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

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

Commented:
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.

http://www.developerfusion.com/show/1845/5/
Naveen SwamyYash Infinite Solutions Private Limited

Commented:
http://www.vbip.com/winsock/winsock_control_ssahmed_03.asp
http://www.codeproject.com/useritems/winsock.asp

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

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

Commented:
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