473,734 Members | 2,647 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

socket.availabl e (socket closed)

Hello,

in msdn stands, that the socket.availabl e 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.Av ailable < RequiredBytes) {}

how to solve?

thanks
Dirk (germany)
May 13 '06 #1
3 3985
> 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(Socke t 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....a nd 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******** ********@TK2MSF TNGP03.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(Socke t 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....a nd 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******** ******@TK2MSFTN GP03.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******** ********@TK2MSF TNGP03.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(Socke t 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....a nd 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
2355
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 able to receive data in server side.I think the client sends the data properly.Somehow receive does not happen. Can someone tell me what could be wrong? My code is part of the sample programs available for socket prgmng in the net. Here is the...
5
45042
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; while(tcpSocket.Connected)
0
2106
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 exception ist being thrown because the connection is already closed. How could I read the data from the buffer? background information: I open multiple connections to my Windows 2003 Web Server (simple HTTP GET).
5
11718
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 1024 with all values set to Null arrive. Other than examine a block of 1024 to see if the entire block is null, is there any other way to determine if , say a chat message "Hi Charlie" has been received completely?
2
702
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 more data to expect). Sometimes, Socket.Available returns 0 but the other end of the connection did not close it ! 2) This class will be used by many other classes so I have to use the
2
4153
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 I get the last chunk of data and am not able to retrieve it anymore cause the socket will be dead. Loop: { socket.Receive <----------- data arrives
2
2806
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: Loop:---------------- Socket.Receive //receive http data chunks Socket.Send //'/r/n' data to check if connection is active ------------------------ The problem is that when connection is closed by the http server, the send socket function...
0
289
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 bevor I receive them, but when remote closes the connection, it ends in an endless loop... it allways return 0... while(socket.Available < RequiredBytes) {}
5
15724
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 to read data from the transport connection" when restart reading the stream with socket.BeginRead in the Sub SocketIncomingMsg. I'm debugging now for weeks, but I can't detect where it's
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
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 we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.