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.
**************
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
http://www.codeproject.com/useritems/winsock.asp
msy be ur server might not be running properly or running on a diff port
ghardy, any luck? Need more help etc?
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
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