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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:50:42+00:00 2026-05-19T00:50:42+00:00

I have a server application and a client application. I’m using socket to communicate

  • 0

I have a server application and a client application.
I’m using socket to communicate between server and client. Everything works fine if there’s only one client connect: uploading, downloading all work well.

But if there’s another client connect (I start the client application again, which means there’re 2 client apps and 1 server app running on my computer), my server starts to mess up: server doesn’t receive file upload from client, client couldn’t download from server.

In server code, I already used multithreading for each client connection so I can’t figure out the problem. Here is my server code:

    private void ServerForm_Load(object sender, System.EventArgs e)
            {

                //...
                Thread th = new Thread(new ThreadStart(ListenForPeers));
                th.Start();
            }

    public void ListenForPeers()
            {
                    serversocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    serversocket.Blocking = true;
                    IPHostEntry IPHost = Dns.GetHostEntry(server);
                    string[] aliases = IPHost.Aliases;
                    IPAddress[] addr = IPHost.AddressList;
                    IPEndPoint ipepServer = new IPEndPoint(addr[0], 8090);
                    serversocket.Bind(ipepServer);
                    serversocket.Listen(-1);
                    while (true)
                    {
                        clientsock = serversocket.Accept();
                        if (clientsock.Connected)
                        {
                            total_clients_connected++;
                            AppendText("Client connected...");
                            Thread tc = new Thread(new ThreadStart(listenclient));
                            tc.Start();
                        }
             }


    void listenclient()
        {
             // start communication
        }

Is there something wrong with my server code that makes it unable to become a multi-clients server system? Help is really appreciated. Thanks in advance.

  • 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-19T00:50:42+00:00Added an answer on May 19, 2026 at 12:50 am

    It looks like you’ve defined your clientSocket as a global variable to be used by all server threads, instead you want it to be a local reference for each thread. You can do this with a ParameterizedThreadStart:

    public void listenForPeers()
    {
      //Setup the server socket
    
      while(true){
        Socket newClient = serverSock.Accept();
        if(newClient.Connected){
          Thread tc = new Thread(new ParameterizedThreadStart(listenclient));
          tc.start(newClient);
        }
      }
    }
    
    void listenclient(object clientSockObj)
    {
      Socket clientSock = (Socket)clientSockObj;
    
      //communication to client via clientSock.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .NET client application that needs to communicate with a server using
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 communication between the client and
I have a client and a server application which communicate over .NET 2.0 Remoting
I have developed a Client/Server application for my current employer and one of the
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

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.