Results 1 to 2 of 2

Thread: winsock help please (SOLVED WITH THANKS)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    129

    winsock help please (SOLVED WITH THANKS)

    Hi all, im trying to get this wonsock fuction to work.

    I have another program which connects to this program via winsock.

    I have placed a Winsock Object on the form called sckMain and gave it a index of Zero to make it a control array.

    Im trying to impliment this from web sites that i have been reading. This part of the program check though a array called bolArray ( a boolean array) which im runnig along side the sckMain array. It check to see if the value ios true (user logged onto that sckMain array) and if not loops around untill it finds a array that is free or false.

    Then it assignes that user that sckMain array number. This is get multiple users being able to log into the main server porgam.

    Im new to Winsocsk and im not sure my logic is sound. This isnt working im getting a OBJECT requierd at Load Winsock(Winsock.i) I tried changeing the Winsock to the name of my winsock array sckMain but that didnt work. Can anyone shine some light ont his for me please?


    VB Code:
    1. Private Sub sckMain_ConnectionRequest(Index As Integer, ByVal RequestID As Long)
    2.    
    3.     For i = 1 To UBound(bolArray)
    4.         If bolArray(i) = False Then
    5.        
    6.             ' load a new winsock
    7.             Load Winsock(Winsock.i)
    8.             ' accept the incoming connection on our new control
    9.             Winsock(Winsock.i).Accept RequestID
    10.             bolArray(i) = True
    11.             txtMessageDisp.Text = txtMessageDisp.Text & vbNewLine & "SYSTEM: Accepted a New Connection on Winsock " & i
    12.             Exit Sub
    13.         End If
    14.     Next i
    15.     ' load a new winsock
    16.     Load Winsock(Winsock.UBound + 1)
    17.     ' accept the incoming connection on our new control
    18.     Winsock(Winsock.UBound + 1).Accept RequestID
    19.     txtMessageDisp.Text = txtMessageDisp.Text & vbNewLine & "SYSTEM: Accepted a New Connection on Winsock " & (Winsock.UBound)
    20.    
    21.  
    22.  
    23.  
    24.     'sckWinsock1.Close 'this resets the socket ready to accept the incoming connection
    25.     'sckWinsock1.Accept requestID 'accept the connection!
    26.  
    27. End Sub
    Last edited by fgp123; Sep 20th, 2005 at 04:58 AM.

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: winsock help please

    I think your doing this the long way around with the boolarray i'm guessing your trying to find a free socket?

    as for your error, the code should be

    VB Code:
    1. Load Winsock(SckMain.UBound + 1)

    Assuming you want to load the socket on the end of the array. Have a look at my code below which will search you winsocks looking for a disconnected client if it cannot find one it will load a new socket this is best for keeping memory use to a minimum

    VB Code:
    1. Private Sub sckMain_ConnectionRequest(Index As Integer, ByVal RequestID As Long)
    2.    
    3. Dim I as integer
    4.  
    5. For i = 0 to sckMain.Ubound - 1
    6.  
    7. If sckMain(i).ConnectionState <> sckConnected
    8.      'Free Socet
    9.       sckMain(i).close
    10.       sckMain(i).accept RequestId
    11.        Exit Sub
    12. end if
    13. doevents
    14. Next i
    15.  
    16.   Load Winsock(SckMain.UBound + 1)
    17.   sckMain(sckMain.UBound).Accept RequestID
    18.  
    19. End Sub

    Try that for the sub, i've just quickly wrote that and I havent used vb 6 for agers. also check out the client/server below it doesnt use the full memory safe method above but its a multi-user server/client chat program with some extra functionality you might like. I wrote it a long time ago though

    Pino
    Attached Files Attached Files

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