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 9269755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:12:10+00:00 2026-06-18T15:12:10+00:00

how create multiple clients with is code program.cs class Program { static void Main(string[]

  • 0

how create multiple clients with is code

program.cs

class Program
{
    static void Main(string[] args)
    {
        Server.ServerCode(5656);
    } 
}

Client.cs

class Client
{
    public static void ClientCode()
    {
            //SOCKET CONNECTION

            //int Port = (int)port;
            Console.WriteLine("......................CLIENT.........................");

            TcpClient client = new TcpClient("127.0.01", 5656);
            NetworkStream clientStream = client.GetStream();
            StreamReader sr = new StreamReader(clientStream);
            StreamWriter sw = new StreamWriter(clientStream);
            sw.AutoFlush = true;
                //CLOSING SOCKET
                clientStream.Close();
                client.Close();
                Console.ReadLine();


    }
}

my server code:

sereve.cs

class Server
{
    public static void ServerCode(object port)

    {

        //SOCKET CONNECTION

        int Port = (int)port;
        Console.WriteLine("................SERVER RUNNING......................");
        TcpListener listener = new TcpListener(IPAddress.Parse("127.0.0.1"), Port);
        listener.Start();
        while (true)
        {
            TcpClient serverSite = listener.AcceptTcpClient();
            if (serverSite.Connected)
            {
                Thread c = new Thread((fileTransfer));
                c.Start(serverSite);
            }
        }
    }

    public static void fileTransfer(object clients)
    {


            Console.WriteLine("new client");*/
            TcpClient server = listener.AcceptTcpClient();//(TcpClient)clients;
            NetworkStream serverStream = server.GetStream();
            StreamReader sr = new StreamReader(serverStream);
            StreamWriter sw = new StreamWriter(serverStream);
            sw.AutoFlush = true;



            //CHECKING USERNAME AND PASSWORD
            Console.WriteLine("Connecting to Client... ");
            string fromClient_u = sr.ReadLine();
            Console.WriteLine("\n  Username: " + fromClient_u);
            string fromClient_p = sr.ReadLine();
            Console.WriteLine("\n  Password: *******");
            if (fromClient_u == "Client1" && fromClient_p == "123456")
            {

                Console.WriteLine("\nClient has Successfully Loged In. ");
                sw.WriteLine("Connection Complete...  ");                       //msg1
                sw.WriteLine("Successfully Connected to the Server.");          //msg2
                sw.WriteLine("Enter Some Informations for File Transfer...");   //msg3

            }
            //CLOSING SOCKET
            serverStream.Close();
            server.Close();
            Console.ReadLine();

    }   

}

its not working. I want the first thread to work and end, then the 2nd thread to start. but this code generates all the three threat at once. my point is , multiple client will be created by this code and they will wait. when the 1st client is done working with the server then the 2nd client will get server connection.

  • 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-06-18T15:12:11+00:00Added an answer on June 18, 2026 at 3:12 pm

    As simple as it may sound, if you want to lock the process until the client ends and then starts the next one, just loop and call it explicitly:

    for (i=0;i<3;i++)
    {
        Client.ClientCode();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to develop a client server system where I can have multiple clients
I am trying to create a socket programming server to handle multiple clients at
I have multiple clients and one server. Server handles each client in one thread.
i'm about to create an app for my client. Multiple clients of him (of
I am trying to create an SSL Socket Server/Client between .NET and Java. In
I am trying to send multiple data from server to client using TCP. I
I have written a TCP server application in C code that can handle multiple
I'm developing a client-server program. I use C# programming language and .net framework 4.
What is the best technology or technique to create server-side code in .NET that
These code is the Server part of my proxy program, and its function is

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.