473,554 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: TcpClient read/write timeouts do not timeout

I just had the problem occur again, with NetworkStream.W rite() doing
its thing with a timeout... and it just sits and waits and waits and
waits... it never times outs. So, I shut the server down just to see
if THAT will make it at least end the function call and continue
(since it's a synchronous call, so the program is delayed until it
returns), and even THAT doesn't make the call end. It just sits and
waits...

Even IF I have a bug in the server, once the server is not even online
or running any more, there is absolutely no reason why this
NetworkStream.W rite() should not end and return. If it has a timeout
of 1 minute, it should return after 1 minute no matter WHAT is
happening.
Hard to say without seeing an actual concise-but-complete code example.
Indeed, but that is going to be nearly impossible to supply. Network
code is just not precise. But, I can say that I'm using the source
code from the TcpClient example on MSDN:
http://msdn.microsoft.com/en-us/libr...tcpclient.aspx
EXCEPT that I implement a delay, and do proper exception handling.
That said, your description isn't all that clear either. Are you having
read/write problems or connection problems? One paragraph says the
former, while another says the latter.
Sorry, the connection IS established, otherwise an exception is thrown
and it wouldn't even GET to the writing/reading stage (see TcpClient
example on MSDN). The issue occurs on reading/writing. It just never
returns from the function call Well, it works 99% of the time, but
when it doesn't work, the call just doesn't end. The server sees the
connection, but never receives any data from the client's Write()
call.
Beware of using the TCP timeout: once the timeout occurs, the socket is no
longer usable.
Thanks for the tip. These are the kinds of things I'd like to know
about.
Depending on your intent, you may be better off
implementing timeout logic yourself elsewhere.
All I desire is to connect to a server, give it some data, it
processes it, and returns the data, and disconnects. A one shot
deal. No repeats. This is why I chose TcpClient, I can: 1. connect,
2. write, 3. read, 4. disconnect, all synchronously, and save the
headaches of writing Asynchronous code.

Zytan
Jul 21 '08 #1
2 4516
On Mon, 21 Jul 2008 09:59:45 -0700, Zytan <zy**********@g mail.comwrote:
[...]
>Hard to say without seeing an actual concise-but-complete code example.

Indeed, but that is going to be nearly impossible to supply. Network
code is just not precise.
I disagree. The _code_ can be, and should be, just as "precise" as any
other code.

It's true that the network environment is less deterministic than code
that is affected only by the goings-on of the local computer. But a) that
doesn't mean that it's not possible to reproduce a problem, and b) it's
not possible to verify that your code is correct, even theoretically,
without seeing the code.

If anything, in a situation like this, it becomes that much more important
for you to investigate the exact circumstances under which the problem
occurs. I think the new name for the Ethereal network analysis tool is
Wireshark. You may want to install that to monitor your network traffic,
so that you can figure out what's different between the cases where the
timeout works as expected, and when it doesn't.
But, I can say that I'm using the source
code from the TcpClient example on MSDN:
http://msdn.microsoft.com/en-us/libr...tcpclient.aspx
EXCEPT that I implement a delay, and do proper exception handling.
What "delay"? What does that mean? Do you mean "timeout"? The two words
don't really mean the same thing, even if they are related. It's
confusing to see them used interchangeably , if that's in fact what you're
doing.

Regardless, the link you provided isn't a complete implementation of a
network i/o (at best, it's one half of the implementation) , nor is it
actually exactly the code you're using. So it's not useful in this
context (even if it did prove useful to you as a starting point).
>That said, your description isn't all that clear either. Are you having
read/write problems or connection problems? One paragraph says the
former, while another says the latter.

Sorry, the connection IS established, otherwise an exception is thrown
and it wouldn't even GET to the writing/reading stage (see TcpClient
example on MSDN). The issue occurs on reading/writing. It just never
returns from the function call Well, it works 99% of the time, but
when it doesn't work, the call just doesn't end. The server sees the
connection, but never receives any data from the client's Write()
call.
>Beware of using the TCP timeout: once the timeout occurs, the socket is
no
longer usable.

Thanks for the tip. These are the kinds of things I'd like to know
about.
Of course, now that I look more closely, I see that you may not be using
the TCP timeout. It depends on the implementation of NetworkStream's
timeout properties, but I suspect that given that they say they only have
an effect for synchronous calls, it's probably implemented at a higher
level than the socket itself.

If I have time, I may look a little more closely at that. Or you can use
Reflector and/or Microsoft's .NET source server to check yourself.

Pete
Jul 21 '08 #2
Hard to say without seeing an actual concise-but-complete code example.
>
Indeed, but that is going to be nearly impossible to supply. Network
code is just not precise.

I disagree. The _code_ can be, and should be, just as "precise" as any
other code.
Yes, you're right.

If anything, in a situation like this, it becomes that much more important
for you to investigate the exact circumstances under which the problem
occurs.
I was trying to, and the issue always occurred on the PCs what I
wasn't running my debugger on. Finally it happened on the PC with my
debugger, but I had already solved the problem right when it happened!

I think the new name for the Ethereal network analysis tool is
Wireshark.
Thanks, I do have Wireshark already, great program!

But, I can say that I'm using the source
code from the TcpClient example on MSDN:
http://msdn.microsoft.com/en-us/libr...kets.tcpclient....
EXCEPT that I implement a delay, and do proper exception handling.

What "delay"? What does that mean? Do you mean "timeout"? The two words
don't really mean the same thing, even if they are related. It's
confusing to see them used interchangeably , if that's in fact what you're
doing.
Sorry, I am using a send and receive timeout within TcpClient, which
gets transferred over to NetworkStream, although the data members are
called different things in the two classes, they are the same thing
AFAIK.

Regardless, the link you provided isn't a complete implementation of a
network i/o (at best, it's one half of the implementation) , nor is it
actually exactly the code you're using. So it's not useful in this
context (even if it did prove useful to you as a starting point).
Agreed. When I shut down the server, and it didn't affect the client,
I knew the issue was in the client-side.
Of course, now that I look more closely, I see that you may not be using
the TCP timeout. It depends on the implementation of NetworkStream's
timeout properties, but I suspect that given that they say they only have
an effect for synchronous calls, it's probably implemented at a higher
level than the socket itself.

If I have time, I may look a little more closely at that. Or you can use
Reflector and/or Microsoft's .NET source server to check yourself.
No no no, I've wasted enough of your time, already!!

The bug was something REALLY STUPID that I did, I wrote about it in
another reply!

Zytan
Jul 21 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3033
by: מורדי | last post by:
Hi, I'm writing a client/server application in which the client send a series of screenshots to the server to be saved using the tcpclient. in most cases the first screenshot is transmitted ok and arrives at the server but from after that i only a couple of KB from the start of the file which cases the picture to display only the very top...
18
4864
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
2
6340
by: Eric Cathell | last post by:
I have an application that I am using to send documents to printers over a network. If the printer is powered off, or in configuration mode, or the client bridge is down, the tcpclient just hangs....I need a way to make it time out and continue to the loop....any know a way i can do that? say if it doesnt connect in 10 seconds to timeout and...
2
8694
by: Lisa Pearlson | last post by:
Hi, I am wanting to write an internet 'server' program. For ease, I want to use PHP-CLI with XINET super server. XINET communicates with the 'server' program via STDIN/STDOUT. I'm not sure how to communicate with the client this way though.. I can open stdin/out as a file, and use read and write operations, as if it were a regular file.....
5
4791
by: Nobody | last post by:
Hi all, I try to write a small client that can handle some TCP communication message. I was wondering how I could use the TcpClient class to manage it. At the first time, I don't want to play with the async methods. My main issue is related about receiving informations back from the server. How can I be sure that the server has...
4
11697
by: rowan | last post by:
I'm writing a driver in Python for an old fashioned piece of serial equipment. Currently I'm using the USPP serial module. From what I can see all the serial modules seem to set the timeout when you open a serial port. This is not what I want to do. I need to change the timeout each time I do a "read" on the serial port, depending on which...
0
1426
by: zhangke007 | last post by:
Hello, everyone, Currently, I have an simple serial communication application using the serialnet.dll tool from Franson company. What this application does is to read the data through the com port in my windows ce 5 based wearable computer. The data is sent from a PIC microcontroller through the RS232 protocol. The scenario is like...
4
20449
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I am wondering if I am using TCPClient class in C#, how to setup timeout value? Timeout I mean, when connects to server for the 1st time, and during <timeoutinterval, if no server response is received, the GetStream method will return will return other than wait forever. thanks in advance,
10
6136
by: Zytan | last post by:
I have a TcpClient. I set the read/write timeouts at 1 minute (in milliseconds). I get a NetworkStream from it and confirm the timeouts still exist. I do a NetworkStream.Write() and then a NetworkStream.Read(). Sometimes it sits and waits -- on the Write() or the Read() -- for 15 minutes before I get fed up and close the app..... I am...
0
7611
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
7535
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...
0
7812
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. ...
0
8051
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7574
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...
0
6161
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5442
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...
0
3579
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...
1
2026
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

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.