1

i'am trying to do Socket programming in C# and now i need to understand that do we need array of sockets in Server-side in order to handle multiple clients or one socket in server-side is sufficient for handling many clients;

And need to configure whether all data from server to client has been reached and the availability of server,discarding the client request .

Do we need to create multiple thread to handle each client also ? and i need to handle each client separetely.

0

5 Answers 5

6

Each connection will require a new socket. As spender says, you only listen with one socket, the socket API will create the other sockets when connection requests come in.

Read the documentation for accept

Sign up to request clarification or add additional context in comments.

Comments

1

One listening socket can service many clients.

Comments

0

You can use one socket to response multiple clients. When a client connet with the server, your application creates a socket to attend this conection.

Comments

0

Please have a look at Writing scalable server applications using IOCP. This's a good tutorial on how to create a robust server application.

Comments

0

you create one listener(welcome socket) which creates a dedicate connection socket for every accepted client.

I think you need some thing like.

private void listen(){

TcpListener listener = new TcpListener(5000);
listener.Start();
while (true)
{
  // Accept a new client
  Socket clientSocket = listener.AcceptSocket();
  //Create a thread for every client.
  ParameterizedThreadStart pThreadStart = new ParameterizedThreadStart(handleClient);
  Thread thread = new Thread(pThreadStart);
  thread.Start(clientSocket);
 }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.