By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,162 Members | 1,416 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,162 IT Pros & Developers. It's quick & easy.

socket.available (socket closed)

P: n/a
Hello,

in msdn stands, that the socket.available property can fire a
SocketException when the remote machine has closed the connection.
why can?

I have to check the number of receivable bytes bevor I receive them, but
when remote closes the connection, it ends in an endless loop...
while(socket.Available < RequiredBytes) {}

how to solve?

thanks
Dirk (germany)
May 13 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> Because when connection is closes value returned by Available property
has no sense. That is why exception is thrown.

the problem is, that no exception is thrown...

i have implemented a method GetPacket(Socket s) that should read data from
the socket, until a whole packet is received...
the socket are in blocking mode, because this runs in its own thread, so I
don't need asynchone operations....and the method should not return before
the whole packet is received.

and sometimes when I read the packet header, the socket.receive method
returns, before the whole header is received.
So i was looking for a way to ensure I can read the whole header.

Dirk
May 13 '06 #2

P: n/a
I've solved it myself...
I receive the data in a loop until my required data is successfully
received...

thanks

"Dirk Reske" <_f*******@gmx.net> schrieb im Newsbeitrag
news:uF****************@TK2MSFTNGP03.phx.gbl...
Because when connection is closes value returned by Available property
has no sense. That is why exception is thrown.

the problem is, that no exception is thrown...

i have implemented a method GetPacket(Socket s) that should read data from
the socket, until a whole packet is received...
the socket are in blocking mode, because this runs in its own thread, so I
don't need asynchone operations....and the method should not return before
the whole packet is received.

and sometimes when I read the packet header, the socket.receive method
returns, before the whole header is received.
So i was looking for a way to ensure I can read the whole header.

Dirk

May 13 '06 #3

P: n/a
That is the way to do it :-)

--
William Stacey [MVP]

"Dirk Reske" <_f*******@gmx.net> wrote in message
news:uY**************@TK2MSFTNGP03.phx.gbl...
| I've solved it myself...
| I receive the data in a loop until my required data is successfully
| received...
|
| thanks
|
| "Dirk Reske" <_f*******@gmx.net> schrieb im Newsbeitrag
| news:uF****************@TK2MSFTNGP03.phx.gbl...
| >> Because when connection is closes value returned by Available property
| >> has no sense. That is why exception is thrown.
| > the problem is, that no exception is thrown...
| >
| > i have implemented a method GetPacket(Socket s) that should read data
from
| > the socket, until a whole packet is received...
| > the socket are in blocking mode, because this runs in its own thread, so
I
| > don't need asynchone operations....and the method should not return
before
| > the whole packet is received.
| >
| > and sometimes when I read the packet header, the socket.receive method
| > returns, before the whole header is received.
| > So i was looking for a way to ensure I can read the whole header.
| >
| > Dirk
| >
|
|
May 14 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.