Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

so far I've been trying a single server+single client udp chat application where both server and client should be able to communicate with each other freely(as in regular chat applications). for this I used the select() function.what I initially got to know about this function is that it demultiplexex between more than one sockets. I haven't had much success in doing so.. My question is: am I using the right approach by using select? If no,then what approach should I use to acheive an asychronous udp chat application?

share|improve this question

1 Answer

You can use threads.

Whenever a client connect to the server you create a thread, this thread will call recv(), when a message is received you can verify its integrity, then the thread gice the hand to a message handler and can go back in recv() mode.

share|improve this answer
so you are suggesting that I should not go for select()? – Aayman Khalid Apr 23 at 6:25
using select implies you will be polling, and polling is almost always a bad thing. – quickly_now Apr 23 at 6:42
@quickly_now: I don't see why select implies polling. Care to elaborate? – Mat Apr 23 at 8:38
Two important points: (1) using a single thread, (2) for an asynchronous application. Then this implies use of select with some kind of timeout, and thats polling (by definition). If select is used with a very long or infinite timeout, then its not polling (its just waiting) but for the progam to do anything useful it would need to use another thread. – quickly_now Apr 24 at 2:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.