Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6468711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:54:55+00:00 2026-05-25T05:54:55+00:00

I have a server application and client application with the functionality already working. Let

  • 0

I have a server application and client application with the functionality already working. Let me show you how I connect my client application to my server app:

                              //SERVER
           //  instantiate variables such as tempIp, port etc...
           //  ...
           // ...    

            server = new TcpListener(tempIp, port); //tempIp is the ip address of the server.

            // Start listening for client requests.
            server.Start();

            // Buffer for reading data
            Byte[] bytes = new Byte[MaxChunkSize];
            String data = null;


            // Enter the listening loop.
            while (disconect == false)
            {
                Console.Write("Waiting for a connection... ");

                // Perform a blocking call to accept requests.
                // You could also user server.AcceptSocket() here.
                client = server.AcceptTcpClient(); // wait until a client get's connected...
                Console.WriteLine("Connected!");

                // Get a stream object for reading and writing
                stream = client.GetStream();

                // now that the connection is established start listening though data
               // sent through the stream..
                int i;
                try
                {
                    // Loop to receive all the data sent by the client.
                    while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                    {

                        // Translate data bytes to a ASCII string.
                        data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
                        Console.WriteLine("Received: {0}", data);
                       // etc..
                       ....

ok now on the client side lets say I want to establish a connection then send some data through the stream

                           //Client
            client = new TcpClient(serverIP, port);

            // Get a client stream for reading and writing.
            stream = client.GetStream();

            //then if I wish to send the string hello world to the server I would do:
            sendString(stream, "Hello world");


     protected void sendString(NetworkStream stream, string str)
    {
        sendBytes(stream, textToBytes(str));
    }

    protected void sendBytes(NetworkStream stream, Byte[] data)
    {
        // Send the message to the connected TcpServer. 
        stream.Write(data, 0, data.Length);
    }
    protected static Byte[] textToBytes(string text)
    {
        return System.Text.Encoding.ASCII.GetBytes(text);
    }

since I am able to send bytes I am able to send files or everything that I want. the technique that I use is that if I send the string file for example to the server then the server will start listening for a file. It will open a stream and write the received bytes to that file. If a different keyword is send the server will start listening on a different method etc..

So when dealing with one server and one client everything works great. Now I want to add more clients and need them to also connect to the server. I know that several connections can be establish on the same port just like we do it with por 80 on websites… I do not know how to manage several connections. so one thing I was thinking was to leave everything as it is. if a connection is established then tell the server to start another thread listening for other connections on the same port. with this technique I will have several threads running plus I just know the basics of multrythreading. If this technique is my best option I will start implementing it. You guys out there are really knowledgeable about all this so it will be nice if someone can point me on the right direction. Or maybe I should listen on several ports. if the server is already connected on port 7777 for example then do not accept connections from that port and start listening on port 7778 for example. I mean there could be so many different ways of achieving what I need and you guys probably know the best way. I just know the basics of networking…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:54:55+00:00Added an answer on May 25, 2026 at 5:54 am

    You could use threading:

    var client = server.AcceptTcpClient();
    var t = new Thread(new ParameterizedThreadStart(AccentClient));
    t.Start(client);
    

    The target method would look like this

    public void AccentClient(object clientObj)
    {
        var client = clientObj as TcpClient;
    
        // Do whatever you need to do with the client
    }
    

    If you are not familiar with multithreading, it is important you learn at least the basics first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Client/Server application, where the Client and Server have some common tables
i have a server - client application that runs on java 1.3; i want
My requirement is I have server J2EE web application and client J2EE web application.
We have a client/server application with a rich client front end (in .Net) and
I have a client/server application that communicates with .Net remoting. I need my clients
I have a client server application that sends XML over TCP/IP from client to
I have a client-server application that uses .net remoting. The clients are in a
I have a client/server application. One of the clients is a CLI. The CLI
I have a client-server application written in Java using CORBA for the communication. The
I have a client server application in which the server and the client need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.