PDA

Click to See Complete Forum and Search --> : Winsock - Connection (array)


Pino
Aug 18th, 2004, 04:15 PM
This amkes no sence to me but on the 2nd connection i get the "ivalid operation at current state" error which means the socket is in use,



Dim x As Long ' counter
If Winsock.UBound < 1 Then 'this is our first connection so accept it
Load Winsock(Winsock.UBound + 1)
Winsock(Winsock.UBound).Accept requestID
End If

For x = 1 To Winsock.UBound + 1 'loops through existing connections to amke sure we have none spare
If Winsock(x).State <> sckConnected Then
Winsock(x).Accept requestID '<<Error here!
Else
If x >= Winsock.UBound Then 'there si none spare so accept on new socket
Load Winsock(Winsock.UBound + 1)
Winsock(Winsock.UBound).Accept requestID
Exit Sub
End If
End If
Next x

i cant understand :( maybe its a simple error?

PINO

Pino
Aug 20th, 2004, 12:44 PM
Any one at all? see any problems?

Wokawidget
Aug 20th, 2004, 01:17 PM
Errr...U can't accept the request twice.
U r accepting it a 2nd time in the For loop.
PLUS...It's for lngIndex = 1 to Winsock.Ubound
Not + 1.

Think this may solve your error problem.

You could always compile my winsock DLL. I wrote this DLL to take away the hassle of winsock control arrays, which suck :(
The DLL also handles data that spans many "packets".

I can see what you're trying to do with the control array, but I don't like it, just me I think, as loads of developers do it your way.

Woof

Wokawidget
Aug 20th, 2004, 01:22 PM
Hmmm...OK, I was wrong. Juts looked at your code again. Ooops.

What line is the error on?

Woof

Pino
Aug 20th, 2004, 01:26 PM
your wrong? well ir emoved the +1 to get this code...




Private Sub Winsock_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim x As Long ' counter
If Winsock.UBound < 1 Then 'this is our first connection so accept it
Load Winsock(Winsock.UBound + 1)
Winsock(Winsock.UBound).Accept requestID
End If

For x = 1 To Winsock.UBound 'loops through existing connections to amke sure we have none spare
If Winsock(x).State <> sckConnected Then
Winsock(x).Close
Winsock(x).Accept requestID
Else
If x >= Winsock.UBound Then 'there si none spare so accept on new socket
Load Winsock(Winsock.UBound + 1)
Winsock(Winsock.UBound).Accept requestID
Exit Sub
End If
End If
Next x

End Sub

i through 4 connections at it and it seems fine? thank you? i think?

muthubose18
Jun 27th, 2008, 03:03 AM
hi,

I'm fairly new to Winsock, and i'm trying to make some simple chat software. I've been looking on google for various Winsock tutorials, but can't find any that are simple enough for a beginner, but also good enough to ensure that i actually learn what is trying to be taught...

If anybody knows a good tutorial, with examples, etc. Then please could you tell me the link.


Thanks & Regards,
Muthukumaramani.S


Note: This is for VB 6

Pino
Jun 27th, 2008, 05:28 AM
Very old thread you should really create a new one!

http://www.vbforums.com/showthread.php?t=297308

That should help thats as simple as you will get.
Good Luck