Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...