473,465 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

socket.available (socket closed)

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
3 3956
> 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: anuradha.k.r | last post by:
hi, I 'v e written both the server and client side socket programs in perl( a very small one).My socket is created and shows that the connection is established with the client.however I am not...
5
by: Morten | last post by:
How do I detect if a client socket is no longer connected to the listen tcp socket ? I have tried with (just an example): --------------------- Socket tcpSocket; ...
0
by: Tomasz Naumowicz | last post by:
Hello Everybody, I have the following problem with Socket: Socket.Available reports data in the buffer (e.g. 1849 bytes) but I can't read it because Socket.Read throws an exception The...
5
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of...
2
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no...
2
by: Nuno Magalhaes | last post by:
I've got a simple problem I guess. How do I know when a connection is terminated without losing any data? I do something like the code below, but sometimes between socket.Receive and socket.Send...
2
by: Nuno Magalhaes | last post by:
How to check for a closed http socket without losing any data? (MSDN says to send something to server). Somewhere in my code (after sending the http header in plain text) I'm doing a loop with:...
0
by: Dirk Reske | last post by:
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...
5
by: Arno | last post by:
reposted with the right microsoft managed newsgroup ID: Sorry for the inconvinience Hi, I've written a class for client-socket connection, but I get a lot of times the error message "Unable...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.