niros Posted July 20, 2005 Posted July 20, 2005 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! Quote
mhildner Posted July 25, 2005 Posted July 25, 2005 Have you tried setting the timeout for receiving?//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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.