473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

TcpClient timeout?

Hi all,

I'm using a TcpClient to talk to a newserver. If I don't send any data for a
while, will the connection timeout, or does something in the TcpClient keep
it alive? If not, and it times out, how do I keep it alive without actually
sending data?

Thanks,
Nov 17 '05 #1
2 8091
Danny,

In .NET 2.0, I believe the TcpClient exposes the underlying socket
through the Client property (it used to be protected, if I remember
correctly). Once you get the socket (by deriving from TcpClient in .NET 1.1
or through the public Client member in 2.0) you can call SetSocketOption,
passing in KeepAlive, to help manage keeping the socket alive.

Mind you, depending on the server (if you don't have control over it or
not), it might actually shut down the connection for some reason or another
(depending on the behavior it wants).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Danny Tuppeny" <gr****@dannytuppeny.commmmmm> wrote in message
news:43***********************@ptn-nntp-reader02.plus.net...
Hi all,

I'm using a TcpClient to talk to a newserver. If I don't send any data for
a while, will the connection timeout, or does something in the TcpClient
keep it alive? If not, and it times out, how do I keep it alive without
actually sending data?

Thanks,

Nov 17 '05 #2
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:e6**************@tk2msftngp13.phx.gbl...
In .NET 2.0, I believe the TcpClient exposes the underlying socket
through the Client property (it used to be protected, if I remember
correctly). Once you get the socket (by deriving from TcpClient in .NET
1.1 or through the public Client member in 2.0) you can call
SetSocketOption, passing in KeepAlive, to help manage keeping the socket
alive.

Mind you, depending on the server (if you don't have control over it or
not), it might actually shut down the connection for some reason or
another (depending on the behavior it wants).


Thanks Nicholas, that helps a lot :)
Nov 17 '05 #3

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

Similar topics

3
by: Daniel | last post by:
TcpClient close() method socket leak when i use TcpClient to open a connection, send data and close the TcpClient with myTcpClientInstance.Close(); it takes 60 seconds for the actual socket on...
2
by: Kirk | last post by:
Hello, I'm trying to get the current date/time from a (S)NTP server. It works with UdpClient class, but not with TcpClient class. I want to use TcpClient because i can set timeout values for...
2
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...
3
by: Peter Stojkovic | last post by:
I have an TcpClient. System.Net.Sockets.TcpClient Everything is working fine. But when the IP-Address is wrong, I DON'T want wait 20seconds for timeout ( seems to be standard ) Is there any...
3
by: Erjan | last post by:
Hi, I am using TcpClient to connect to a device which does not talk NetBios. The TcpClient tries first to do something with Netbios. This probably failes on a timeout and then TcpClient sets up...
0
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...
4
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...
10
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...
2
by: Zytan | last post by:
I just had the problem occur again, with NetworkStream.Write() 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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,...

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.