Note that there are some explanatory texts on larger screens.

plurals
  1. POC# problem with multi-clients server application
    primarykey
    data
    text
    <p>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. </p> <p>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. </p> <p>In server code, I already used multithreading for each client connection so I can't figure out the problem. Here is my server code:</p> <pre><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 } </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload