Results 1 to 7 of 7

Thread: Winsock - Connection (array)

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Winsock - Connection (array)

    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,

    VB Code:
    1. Dim x As Long ' counter
    2. If Winsock.UBound < 1 Then 'this is our first connection so accept it
    3.        Load Winsock(Winsock.UBound + 1)
    4.        Winsock(Winsock.UBound).Accept requestID
    5. End If
    6.  
    7. For x = 1 To Winsock.UBound + 1 'loops through existing connections to amke sure we have none spare
    8.    If Winsock(x).State <> sckConnected Then
    9.           Winsock(x).Accept requestID '<<Error here!
    10.    Else
    11.    If x >= Winsock.UBound Then 'there si none spare so accept on new socket
    12.             Load Winsock(Winsock.UBound + 1)
    13.             Winsock(Winsock.UBound).Accept requestID
    14.             Exit Sub
    15.        End If
    16.    End If
    17. Next x

    i cant understand maybe its a simple error?

    PINO

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    Any one at all? see any problems?

  3. #3
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    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

  4. #4

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787
    your wrong? well ir emoved the +1 to get this code...


    VB Code:
    1. Private Sub Winsock_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    2. Dim x As Long ' counter
    3. If Winsock.UBound < 1 Then 'this is our first connection so accept it
    4.        Load Winsock(Winsock.UBound + 1)
    5.        Winsock(Winsock.UBound).Accept requestID
    6. End If
    7.  
    8. For x = 1 To Winsock.UBound 'loops through existing connections to amke sure we have none spare
    9.    If Winsock(x).State <> sckConnected Then
    10.           Winsock(x).Close
    11.           Winsock(x).Accept requestID
    12.    Else
    13.    If x >= Winsock.UBound Then 'there si none spare so accept on new socket
    14.             Load Winsock(Winsock.UBound + 1)
    15.             Winsock(Winsock.UBound).Accept requestID
    16.             Exit Sub
    17.        End If
    18.    End If
    19. Next x
    20.  
    21. End Sub

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

  6. #6
    New Member
    Join Date
    Jun 2008
    Posts
    1

    Re: Winsock - Connection (array)

    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

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Winsock - Connection (array)

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width