Results 1 to 5 of 5

Thread: Multiple Clients?

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    47

    Resolved Multiple Clients?

    What is the best way for a tcp server to accept multiple tcp clients? The clients have no way of knowing what ports are already used by the server. Is there some way to setup portforwarding on the server?
    Last edited by qazwsx; Jan 13th, 2008 at 03:39 PM.

  2. #2
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: Multiple Clients?

    Well most servers use a constant port number such as 10000 or something like that. Then the user connects to the server's ip address and that port number. The port number may be in the program by default or available on the program/game's website.

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    47

    Re: Multiple Clients?

    I understand the constant port number. But if there are multiple clients can they all be connected on the same port?

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Multiple Clients?

    Yes.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2007
    Posts
    47

    Re: Multiple Clients?

    Could you explain to me how to do that?

    This is what I have so far:

    Server

    Code:
    Dim client(9) As TcpClient
        Dim server As TcpListener
        Dim listthread As New System.Threading.Thread(AddressOf accept)
    Sub createthread()
            buttonstate(True)
            Dim i As Integer
    
            For i = 0 To client.Length - 1
                client(i) = New TcpClient()
            Next
    
            server = New TcpListener(IPAddress.Any, 2999)
    
            server.Start()
    
            listthread.Start()
    
    
        End Sub
     Sub accept()
            Dim j As Integer = 0
            Dim i As Integer
            While 1
                For i = 0 To client.Length - 1
                    If client(i).Client.Connected Then
                        j = i
                        Exit For
                    End If
                Next
                Try
                    server.Start()
                    client(j) = server.AcceptTcpClient()
                    setcresults(client(j).Client.RemoteEndPoint.ToString & ": Connected")
                    Dim stream As NetworkStream = client(j).GetStream
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            End While
        End Sub
    Client

    Code:
    Dim networkstream As System.Net.Sockets.NetworkStream
        Dim tcpclient As New Net.Sockets.TcpClient()
    Sub connect()
            While 1
                Try
                    Try
                        tcpclient.Connect("sccrstvn93.no-ip.org", 2999)
                    Catch ex As Exception
                        MsgBox(ex.Message)
                    End Try
    
    
                    While 1
                        networkstream = tcpclient.GetStream
                        acceptdata()
                        executecommand(clientdata)
                    End While
    
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            End While
        End Sub

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