473,385 Members | 1,326 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,385 software developers and data experts.

How do you keep a TCPClient alive.

I'm writing a remote client in C# that connects to a remote connection
manager via a TcpClient. The connection and handshake work perfectly.
I must then remain connected and respond to the connection manager's
request. I've tried calling read in a loop right after the handshake
but the first time the socket's read method is called, the socket
reports it's disconnected. I've created a TcpClientEx class inheriting
from the TcpClient and set the KeepAlive socket option but that didn't
change anything. I know the connection manager isn't closing the
connection. How can I keep the connection alive and waiting for
commands? Thanks in advance for your help!

Nov 17 '05 #1
5 10457
Can you send AYT (Are you there) messages?

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
-------------------------------------------------------------------------------------------

"Darrell Sparti, MCSD" <we*******@bacausa.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
I'm writing a remote client in C# that connects to a remote connection
manager via a TcpClient. The connection and handshake work perfectly.
I must then remain connected and respond to the connection manager's
request. I've tried calling read in a loop right after the handshake
but the first time the socket's read method is called, the socket
reports it's disconnected. I've created a TcpClientEx class inheriting
from the TcpClient and set the KeepAlive socket option but that didn't
change anything. I know the connection manager isn't closing the
connection. How can I keep the connection alive and waiting for
commands? Thanks in advance for your help!

Nov 17 '05 #2
The connection manager sends them to me and I must respond. That's why
I have to keep reading from the socket basically listening for the
server's are you there messages and responding to them. There are
other commands the server sends as well that I need to respond to.
Thanks!!!

Nov 17 '05 #3
Thank you Sahil, I found the problem. Once the connection is
established, I capture the network stream and maintain it instead of
the socket itself. The network stream manages the socket for me. I
can loop checking for CanRead and DataAvailable. When I close the
socket, the network stream is closed with it so all works fine now.
Thanks again for your help!!!!

Nov 17 '05 #4
Thanks Sahil, I figured it out. I maintain the network stream instead
of the socket. Then I just check the CanRead and DataAvailable
properties in my loop. When I finally disconnect the socket, it
automatically closes the stream for me. Thanks again for your help!!!

Nov 17 '05 #5
Fantastic .. glad it worked out.

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
----------------------------------------------------------------------------

"Darrell Sparti, MCSD" <we*******@bacausa.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Thanks Sahil, I figured it out. I maintain the network stream instead
of the socket. Then I just check the CanRead and DataAvailable
properties in my loop. When I finally disconnect the socket, it
automatically closes the stream for me. Thanks again for your help!!!

Nov 17 '05 #6

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

Similar topics

1
by: David | last post by:
This is called "evil hack problem" because my problems are due to me trying to do an evil hack. Please don't judge me, just believe that there are reasons for what I'm trying to do :-) I've got...
1
by: cppdev | last post by:
Hello, After reading a few articles, http://blogs.gotdotnet.com/cbrumme/PermaLink.aspx/e55664b4-6471-48b9-b360-f0fa27ab6cc0...
0
by: David Dvali | last post by:
Hello. I'm developing some project which requests persistent TCP connection to the server. I'm using TcpClient class for implementing this task and now I want to do following: I want to check...
2
by: Danny Tuppeny | last post by:
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...
1
by: Nuno Magalhaes | last post by:
With the sniffer ethereal I get a lot of Connections Keep Alive in some sites like google.com and that returns me the Content-Length in the HTTP response header. When the connection is Close I...
1
by: Mathijs | last post by:
Hi, I have a small Compact Framework tcpclient application (c#). This is my connection procedure: tcpclient = new TcpClient(ip, port); stream = tcpclient.GetStream(); Sent("HELLO");...
7
by: mail747097 | last post by:
I would like to keep IIS alive on my web site and prevent Application_End from occuring in global.asax. Any ideas?
6
by: Bjoern Schliessmann | last post by:
Hello, I'm currently trying to implement a simulation program with Kamaelia and need a reliable TCP connection to a data server. From Twisted, I know that a method is called if the connection...
0
by: richard.krehbiel | last post by:
I've been googling for half a day now and have found answers on both sides of the argument. Baiscally it's this: I am using PHP 5.0.4 (I can upgrade if that's a solution) as an ISAPI module under...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.