Winsock & Threads

Hey There...

I am writing a small chat program: 1 host, multiple clients.

I managed the message-receiving with an FD_SET and select() to check for new connections and new messages...

Buf i am wondering how i could get them new incoming connections in the main thread and then pass the message-sending/receiving to another?...

Any suggestions... i already tried something but that did not work :(
Last edited on
What I did once was wait for incoming connections in thread B (now that I was perusing the code, I noticed that I didn't put a mutex around the push_back() to the vector) and wait for commands from the clients in a loop in thread A. A dedicated thread for each client waited for data and notified thread A that new data was ready to be read from a buffer.
It wasn't my most robust program, but it was okay for first try with networking. It was also a prank on a coworker that allowed anyone in the office to remotely change his wallpaper to anything we uploaded. Heh heh heh.
Last edited on
i think u did the data sending on 1 socket?... did u use the send to-function or how did u make that?... or did u open a socket for every accepted connection?...

at the moment my program got the accept socket and returns a new socket for every accepted connection over accept-socket...

how can i make more clients use the same socket for sending and receiving data?...
as far as i know "accept()" returns a new socket which the incoming client will use...
Last edited on
I thought I did everything on a single socket, but I just found a std::vector<SOCKET>, so I guess every accept() gave me a new socket. This code is over a year old, so it doesn't surprise me that I don't remember.
As for sending, I used send().
Do you realize any solution , how i could get all the Clients stuff over 2 sockets (1 cor connection, 1 for transmission)?... i did google around but didnt find anything fitting...

Topic archived. No new replies allowed.