Click to See Complete Forum and Search --> : Trouble with WinSock SendData method!!
Captain Pinko
Aug 17th, 2000, 02:05 AM
I ahve recently been acquainting myself with the WinSock control. I have used the tutorial from http://www.vbweb.co.uk\controls\win_sock.htm to create a WinSock program that uses TCP/IP protocol to communicate between two forms on the same computer. It works. When I tried similar code but instead having the RemoteHost property set to another computer the SendData method gives me a Run-Time Error # 40006. One thing I did notice is that on the project that works WinSock.State = 7 and on the one that doesn't WinSock.State = 9. I'm pretty sure that the errors lies there because there is no error after the Connect Method. Please give an help you can. If you have any idea or just shoot off a few ideas you might reach me on ICQ, nick name = Captain Pinko.
thnx
7 = sckConnected
9 = sckError
Error 40006 = sckBadstate
sckBadState, Wrong protocol or connection state for the requested transaction or request.
You are probably trying to send data or getdata while you are not (yet) connected to the other machine(Connecting to antoher machine goes way slower then connecting to your own), wich would be right because you got an error (state = 9)
Look what the Winsock_Error event returns (it should give some sort of error)
Hope it helps,
Captain Pinko
Aug 18th, 2000, 08:33 PM
Then how do I know if I am connected with the other
computer. I always figured it was pretty much instantaneous.
How long should it take? What should I do? Does anybody know what all the state constants mean\are? Please post...
Example:
Private Sub Command1_Click()
'Connect
Winsock1.Connect "127.0.0.1", 9876
'Wait
Do Until Winsock1.State <> sckConnecting
DoEvents
Loop
'Are we connected
If Winsock1.State = sckConnected Then
'Yes we are
Winsock1.SendData "MyData" & vbCrLf
Else
'Nope we aint
End If
End Sub
Captain Pinko
Aug 19th, 2000, 10:49 PM
Do you know what all the winsock state constants are?
yes indeedy!
Constant Value Description
sckClosed 0 Default. Closed
sckOpen 1 Open
sckListening 2 Listening
sckConnectionPending 3 Connection pending
sckResolvingHost 4 Resolving host
sckHostResolved 5 Host resolved
sckConnecting 6 Connecting
sckConnected 7 Connected
sckClosing 8 Peer is closing the connection
sckError 9 Error
vbweb
Aug 9th, 2001, 09:38 AM
Just a note to say that the tutorial mentioned @ vbweb has been moved to
http://www.vbweb.co.uk/show/78/
:)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.