Results 1 to 12 of 12

Thread: Winsock troubles

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    New Hampshire, USA
    Posts
    127

    Thumbs up Winsock troubles

    How can I connect to a winsock server that will have multiple connections? I cannot figure out how the ports would work for something like this. Only one person can be connected per port, correct? I have tried many things...any ideas? If you need more info just ask. Thanks.
    Last edited by ddivers; Sep 11th, 2002 at 06:23 PM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    New Hampshire, USA
    Posts
    127
    VB Code:
    1. For intC = 0 To 9
    2.     If intC <> 0 Then _
    3.         Load tcpClient(intC)
    4.     tcpClient(intC).RemoteHost = "127.0.0.1"
    5.     tcpClient(intC).RemotePort = (1001 + intC)
    6. Next intC
    This is what I use to initialize. The server portion is going to have the option for up to 10 connections, ports 1001-1011. I cannot figure out how to make it attempt to connect to port 1001, if that fails, move on to 1002, then 1003, etc. and have it stop when it connects.
    Last edited by ddivers; Sep 11th, 2002 at 10:50 AM.

  3. #3
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    In your example, you would need a listener for every port that the client controls are attempting to connect to.

    The server only needs 1 listener tcpServer(0). As connection requests come in, load a new tcpServer(n) as needed and accept the request with the new winsock control. All will connect using the same port that the listener is using.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    New Hampshire, USA
    Posts
    127
    I think I see what you are saying, but im not totally sure, could you please elaborate.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    New Hampshire, USA
    Posts
    127
    10 clients could all connect using the same port? how does the server keep track of who is sending the data and replying?

  6. #6
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    The Data_Arrival sub provides the index to the correct control.

    Try playing around with the attached app, you will see what I am talking about. You will have to change the RemostHost in the client code, and you may have to change the port number in both.
    Attached Files Attached Files

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    New Hampshire, USA
    Posts
    127
    I'm not on a computer with vb right now, but I will take a look at it tonight. Thanks again.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    New Hampshire, USA
    Posts
    127

    Thumbs up

    Not only is it working, but I understand WHY it is working. Thanks a bunch!

  9. #9
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    Originally posted by ddivers
    Not only is it working, but I understand WHY it is working. Thanks a bunch!
    Thanks I'm glad it helped. I have been working on that to be a tutorial of sorts on sockets programming and sending data structures in a mixed platform/language environment.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    New Hampshire, USA
    Posts
    127

    Question

    The way my program is set up, I have 1 server and 10 clients. Each of the clients will be able to communicate with the server, and the server only. I would like to be able to have a new form be created each time a new client connects. As it is now, I have no trouble communicating with the 10 client programs, but all 10 of my display/send text boxes are on the same form. Is there some way I can create a form control array? If you need any more information, please ask.

  11. #11
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    Sure! I do it with MDI child forms in one of my apps. I keep an Access database with info about the production machines that we have and use the info to build several menus in the parent form. Then based on the menu item selected, I load a form for the selected system.

    In my parent form, I declare the forms as:
    VB Code:
    1. Dim NewStatus(giMaxNodes)      As frmStatus
    2. Dim NewExceptions(giMaxNodes)  As frmExceptions
    3. Dim NewRequest(giMaxMoniForms) As frmMoniRequest
    Here is the entire menu click code that will load Process Exceptions form for the selected system.
    VB Code:
    1. Private Sub mnuNodeE_Click(index As Integer)
    2.    ' Send request for status of specified node
    3.    
    4.    frmMoniMDI.MousePointer = vbHourglass
    5.    
    6.    ' disable the menu item for displayed node
    7.    If index <= giNodeCount Then
    8.       mnuNodeE(index).Enabled = False
    9.    End If
    10.    
    11.    ' save index in a global for the initial IP send
    12.    giFormNum = index
    13.    
    14.    ' create a new form for the selected node
    15.    If bNECreated(index) = False Then
    16.       Set NewExceptions(index) = New frmExceptions
    17.       bNECreated(index) = True
    18.    End If
    19.    Load NewExceptions(index)
    20.    NewExceptions(index).Caption = mnuNodeE(index).Caption & " Exceptions"
    21.    NewExceptions(index).Tag = index
    22.    
    23.    ' display the form
    24.    NewExceptions(index).Show
    25.    
    26.    frmMoniMDI.MousePointer = vbDefault
    27.    
    28. End Sub
    Each form builds the UDT to be sent to the host, but all of the sockect I/O is done in the parent form. I use the form's Tag property to store the index to the form. The form stores it's Tag in a field in the 52 byte header of the UDT so that the parent knows were to send the reply info.

    If you need more details, let me know.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Jul 2001
    Location
    New Hampshire, USA
    Posts
    127
    Thanks I'll look into it!

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