I am writing client in c++ (socket programming) but the server has two options to send to client request and also server can send data on specific port(lets say port ZZ). I want the client listening on port ZZ non-blocking. How can I do it? Would select() command will help me? or is there any other technique to implement this. Thanks
Asked
Active
Viewed 338 times
2 Answers
1
You can use either the non blocking mode or you use a very small block time (like one millisecond).
To active non blocking mode you have to configure your socket alike.
See Beejs Guide to socket Programming to learn how to do it.

Quonux
- 2,975
- 1
- 24
- 32
-
Thanks for answer. How can I put small block time? – Aqeel Raza Apr 06 '13 at 21:19
-
see for example here http://stackoverflow.com/questions/4181784/how-to-set-socket-timeout-in-c-when-making-multiple-connections (linux), on windows you need to check out the winapi socket functions (winsock) – Quonux Apr 06 '13 at 21:22
0
Maybe use multithread is a better choice. You can use recive reponse tin the main thread and listen the port ZZ in another thread.

Expressway Retrograding
- 144
- 1
- 7
-
yeah I am doing same but when I create thread to listen on port ZZ. it just stuck in the while loop. – Aqeel Raza Apr 07 '13 at 10:39
-
What kind of protocol do you use? TCP or UDP? If you use tcp, you must establish a connection first. – Expressway Retrograding Apr 07 '13 at 12:17