I want to make a simple chat program after I got my first winsock program to work. The thing with chat is that the receiving part seems to work simultaneously with the sending part, but the thing is `recv()` seems to hold until it receives something(like any stdin function, I suppose) and so during that time I can't call any stdin function to do the sending part. Taking turns seem odd.

Assuming I could get them to connect and without a sort of main server, how could I perform both receiving and sending(or at least input). A common server is set for a later endeavor.

I also figure I could do this on GTK+, but I'm using VS since C::B is a pain with winsock and auto-completion is broken. Also, its a good opportunity to learn some console formatting.(the mingw installation had this cool thing where it can update only a given length in the console instead of reprinting everything.)

In general, it is easier to run client/server test code in separate consoles. However, this requires a separate client and server. If you've combined them then you really have no choice but to force a particular order of operations and to 'take turns'

Since the thread appears in the C forum, I can't recommend boost::asio (and I didn't). Depending on which platform you are targeting, you may look at the IO completion ports, WaitForMultipleObject(), [e]poll(), or select().
The latter is really the largest common denominator of all IO muxing techniques; it is somewhat cumbersome, it may lead to a seriously inefficient system, it may even be misused to non-portability. However, in my opinion, it is the best starting point for applications such as yours.

This article has been dead for over six months. Start a new discussion instead.