Advertisement

Chatting with winsock

Started by October 06, 2002 09:53 PM
1 comment, last by ihatepunkrock069 22 years, 4 months ago
I have a totally working client and server that connect and can send a text message. i have a packet.h, in which i put #define GENERAL_PACKET 1 #define TEXT_MSG 2 class GeneralPacket{ public: int iSize; int iType; }; class TextMsg : public GeneralPacket{ public: char message[512]; }; i''m just confused about the login behind having the two chat, obviously i can''t put something like while(true){ send(); recv(); } does it have to be asynchronous? i just wanna be able to chat nonstop until one of them exits
Options

- polling for read/writability with select() and a zero-second timeout
- non-blocking sockets
- asynchronous sockets
- multithreaded application.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
When someone sends a chat message, there is no guarantee that the person who received it will want to respond. So, you should break down the communications into 2 separate operations.

(Send) When a user types up a chat message and clicks Send, the chat message is delivered to the recipient(s).

(Receive) When a chat message arrives, the message is added to the chat window.

This way, the 2 (or more) chatters can carry on a conversation, or 1 can blab all day while the other just ''listens''. Or somewhere in-between.

I always use non-blocking sockets.
--- "A penny saved never boils."

This topic is closed to new replies.

Advertisement