How to connect multiple sockets in C
Go to solution
Solved by BuckGup,
8 hours ago, Eigenvektor said:I can't help you with C in particular, but the general idea is this:
The server does "accept" to wait for incoming connections. This call is blocking, so you may want to do this on a separate thread. As soon as a client connects to the socket, you start a new thread to deal with this client and loop back to "accept", so that the server can accept further connection attempts.
while(!shutdown) { // This blocks, until a client connects final Socket socket = serverSocket.accept(); // Use the returned socket to communicate with the client on a separate thread new Thread(() -> { communicate(socket); }).start(); // Loop back to accept further connections }
I eventually figured it out. I can have multiple clients on a single socket I just need to assign the connfd uniquely to each client as they come in. Once I did that I was able to compute on each node and return what they got to the head server
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now