Question accept multiple clients?

quddusaliquddus

Active member
Joined
Nov 20, 2007
Messages
25
Programming Experience
Beginner
Hi! :) I am writing a server application. A thread is created which runs the code snippet below.

Q [1] Will this accept multiple clients? (I am unable to test this as I only have access to one PC). If not, then how can I modify it to do so?

Q [2] How can I test multiple clients for a server one one PC running the server?

Thanks

quddusaliquddus

VB.NET:
 Listener.Start()

        While Listener.Pending = False
            Client = Listener.AcceptTcpClient()
            Dim Stream As NetworkStream = Client.GetStream()

            While Stream.CanRead

                Dim Header As Byte() = New Byte(1) {}
                Stream.Read(Header, 0, 2)

                Dim DataPackage As Byte() = New Byte() {}

                While (DataPackage.Count - 1 < Header(0))

                          DataPackage = New Byte(Header(0)) {}
                          Stream.Read(DataPackage, 0, DataPackage.Count)

                End While

                Select Case Header(1)

                    Case 0

                    Case 1

                    Case 2

                End Select

            End While
 
Given that the TcpListener supports asynchronous operations, you can accept connections in the background without having to explicitly create a new thread. Here's an example, which also includes multiple client connections.

Asynchronous TcpListener & TcpClient

Unfortunately for you, the solution was created in VS 2008. If you're using a full version of VS and you don't want to pay to upgrade then you have a few options:

1. Manually edit the SLN and VBPROJ files to allow them to open in VS 2005.
2. Create a new solution containing new projects and then import the existing items from my solution.
3. Install a newer edition of VB Express. You probably can't get 2008 anymore but 2010 will do fine. You can install it without affecting your VS 2005 installation. It will upgrade my 2008 solution to 2010, but the code will remain unchanged.

If you do try to stick to 2005, there may be some small changes to the code required.
 
Back
Top