Re: .NET Socket



Rahul Anand <RahulAnand@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

> <CODE>
>
> Byte[] bytesReceived = new Byte[256];
> do
> {
> bytes = s.Receive(bytesReceived);
> strReceived += Encoding.ASCII.GetString(bytesReceived, 0, bytes);
> }
> while (bytes > 0);
>
> </CODE>
>
> But later I noticed that if in last iteration the bytes come to be less than
> 256 i.e. when I have received all data the next receive call causes the
> execution to block as receive has nothing to receive.

So the problem you're trying to solve is preventing a call to
Socket.Receive from blocking indefinitely?

If so, you're approaching the problem incorrectly. You should use the
above code in a worker thread, *allowing* it to block indefinitely. You
can call Socket.Shutdown in another thread to interrupt that blocking call.
.



Relevant Pages

  • Re: increasing counter whithin loop?
    ... > the loop? ... there's nothing preventing you from doing e.g.: ... # set skip to true to skip the next iteration ... Prev by Date: ...
    (comp.lang.ruby)
  • Re: Unit Testing Non-Believer
    ... > To look at it from the other extreme viewpoint, and according to this, ... You'll have to put your foot ... And you have to do that on every iteration in any ... If the user was going to interrupt you it was because he wanted ...
    (borland.public.delphi.non-technical)
  • I dont understand what glob does here
    ... invocation, I would have seen one "file" in each iteration, not 2 ... Why does the behavior change between iterations of the foreach loop ... I've read through glob and File::Glob and I haven't seen anything ... Prev by Date: ...
    (comp.lang.perl.misc)
  • Re: Strange query problem php/mysql
    ... iteration its contents are unpredictable. ... Fix this first. ... chars. ... Prev by Date: ...
    (comp.lang.php)
  • Re: removing list comprehensions in Python 3.0
    ... Hrm, okay, so generators are generally faster for iteration, but not ... for making lists(for small sequences), so list comprehensions stay. ... Prev by Date: ...
    (comp.lang.python)