using like "select" function

niros

Newcomer
Joined
May 25, 2004
Messages
23
Hi, I am familiar with the select function from c++.
I wanted to know if someone knows a way to listen to a socket for example with a something like the select function (that has a timeout as well).
I need to receive unknown sized data from a socket in a non-blocking way , Therefore I am not sure that using "Socket.BeginReceive" is the best solution for me, because I will want to receive each time one byte because I don’t know the data size, which results alot of callbacks.
I don’t want to use "Socket.Receive" because it’s a blocking function and then in case that I will want to cancel the working thread it will be a problem.
Is there a way to do something like "select" that blocks for a requested time, or until data received?
Does someone have some other solution to recommend me? Thanks!
 
Have you tried setting the timeout for receiving?
Code:
//Receive operations will timeout if not received within 1000 milliseconds.
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 1000);
Note, I haven't tried it, as I usually use asynchronous methods, but it should block for one second.
 
Back
Top