Link to home
Start Free TrialLog in
Avatar of Ready4Dis
Ready4Dis

asked on

VB Winsock Control Errors.... Invalid Operation At Current State

Alright, well, I'm trying to do a Client/Server application in VB and I'm having problems getting my TCP/IP connection to work.

First off... Visual Basic 6, Win NT Service Pack 6.

Here is the layout...
Server:
winsock.localport 1001
winsock.listen

Client:
winsock.remotehost = "127.0.0.1"  'Local machine...
winsock.remoteport = 1001
winsock.connect

So far so good.
But, when my server gets to... winsock_connectionrequest the program runs the routine somewhat correctly.  First, the routine looks like this...

private sub Winsock_ConnectionRequest(ByVal RequestID as Long)
'  Verfied it got here by adding msgbox "Check"
   Winsock.Accept ReqeustID
'  Doesn't make it here, give me the Invalid Operation At Current State.
'Checked state right before I Accept the Request and it's 2
'Or Listen, depends on how you like to look at it.
end sub

So, my question is, why won't it let me accept the connection?!?!

I'm starting to think that it's a problem with Windoze... because I've written similar programs before using Visual Basic under Win 98 and didn't have these problems... I couldn't even get UDP to work correctly here!

But if anyone can give me a way (preferably simple :) that will work under windoze nt service pack 6 (and windows 98, I want it to go from this machine to my windoze machine at home), I will give you 100 points... if that's not enough, then I can easily raise it, as this is only my third question, I have more than enough points to spare if you can help.
Avatar of JonFish85
JonFish85

#1, if you copied that code out of VB, the "Winsock.Accept RequeustID" is spelled wrong (or is that just what you typed here?)
Maybe, the socket isn't yet opened?
Anyway, here's a Winsock HTTP Server that works: http://robbert.waphosts.net/winsockhttpserver.zip
(Is saw the RequeustID too but moved early from it; can't be...)
ASKER CERTIFIED SOLUTION
Avatar of royster
royster

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
Actually use the constant "sckClosed" instead of 0. They say to use constants instead of values so the code will be more compatible with VB.Net if you ever upgrade to it.
yeha.. you have to close the socket first...

on the accepting object
wskAccepting.close
doevents
wskAccepting.accept requestID

That will work
you should really look at using the control array style of winsock, to let your listener remain listening then your client / server can accept multiple connections
Avatar of Ready4Dis

ASKER

Typing Error... sorry about that ;)

Don't want it to work with multiple connections.. it's just for a single user (me) to connect.  I have written code to grab screen shots, check for sections that have been changed, and send them to client.  Just can't get the damn connection to work correctly ;).  Kinda re-writing PC Anywhere... except to run through a server.  Needs to go like this...
From my Home PC, through my Home Server.. to my Work Server to my Work Computer.  I also have code to send key-strokes... just can't get this winsock thing to work.  The status of the Winsock before I call Winsock.Accept requestID.. is 2 (or listening).  I will try to Winsock.Close before I do it.

Wow, that worked... son of a... you know.

I tried that before too, and I didn't realize that it was working, I thought that if you did that, it couldn't accept correctly (have only worked with UDP before, but is much slower than tcp/ip, and much higher loss rate).

Thanks a bunch everyone.

Since royster is the first one to give me the correct response he is credited.  I raised it to 150 points just because I have more points that I need. :)  Happy coding

Billy

I am posting another question about key strokes if anyone else wants points... :)
If it works, it's Excellent ;)  Especially if it's only 1 line of code.
sounds like a trojan to me...