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

Telling when a Socket is Disconnected

Im working on writing an FTP application in C# to get a good
feeling for the .NET language and how threading / networking
classes all work. Thus far I have it working for the most
part in PASV mode. The only problem I have encountered is
when the server ends the connection, the
socket cant tell and attempts to continue reading data
infinitely.

Basically... in PASV mode, the FTP server opens a random
port > 1024 and the client connects to that port. When file
transfer is completed the server drops the connection on
that port. However... the port stays open for another
connection for data transfer.

So... what I think is happening is when the connection is
dropped, the socket reconnects and attempts to continue
reading data. There is no more data. I unfortunately can
not base breaking out of the loop based upon data being
available on the socket because it may take packets
longer than others to arrive.

There is a success message transferred to the control
connection of the FTP client upon success of the file
transfer. That means that the server has sent all the
packets out... but doesnt mean the client has recieved them
all.

I see my solutions as being setting a boolean variable upon
receipt of the success message from the server... but how
can I tell when the data is done???? Would I need to have a
timeout after an arbitrary amount of time??? Is there any
way to tell that the connection has dropped???
Apparantly the socket is reconnecting on its own after the
completetion of the data transfer... is there a way to set
it to NOT do this????
Nov 15 '05 #1
3 2149
I didn't read the whole posting .. but I guess you are missing the ping..
that is you have to have a ping message from the client to the server going
at a periodic rate and a timer should keep on looking at it and check
whether the ping message successfully recieved the server if the response
didn't come after significant amount of time period that say that the
connection is dropped.

Hope this help you

Nirosh.

"Nagash01WS6" <ia*****@fooz.com> wrote in message
news:Xn***************************@65.32.1.8...
Im working on writing an FTP application in C# to get a good
feeling for the .NET language and how threading / networking
classes all work. Thus far I have it working for the most
part in PASV mode. The only problem I have encountered is
when the server ends the connection, the
socket cant tell and attempts to continue reading data
infinitely.

Basically... in PASV mode, the FTP server opens a random
port > 1024 and the client connects to that port. When file
transfer is completed the server drops the connection on
that port. However... the port stays open for another
connection for data transfer.

So... what I think is happening is when the connection is
dropped, the socket reconnects and attempts to continue
reading data. There is no more data. I unfortunately can
not base breaking out of the loop based upon data being
available on the socket because it may take packets
longer than others to arrive.

There is a success message transferred to the control
connection of the FTP client upon success of the file
transfer. That means that the server has sent all the
packets out... but doesnt mean the client has recieved them
all.

I see my solutions as being setting a boolean variable upon
receipt of the success message from the server... but how
can I tell when the data is done???? Would I need to have a
timeout after an arbitrary amount of time??? Is there any
way to tell that the connection has dropped???
Apparantly the socket is reconnecting on its own after the
completetion of the data transfer... is there a way to set
it to NOT do this????

Nov 15 '05 #2
Nagash01WS6 <ia*****@fooz.com> wrote in message news:<Xn***************************@65.32.1.8>...
Im working on writing an FTP application in C# to get a good
feeling for the .NET language and how threading / networking
classes all work. Thus far I have it working for the most
part in PASV mode. The only problem I have encountered is
when the server ends the connection, the
socket cant tell and attempts to continue reading data
infinitely.

Basically... in PASV mode, the FTP server opens a random
port > 1024 and the client connects to that port. When file
transfer is completed the server drops the connection on
that port. However... the port stays open for another
connection for data transfer.

So... what I think is happening is when the connection is
dropped, the socket reconnects and attempts to continue
reading data. There is no more data. I unfortunately can
not base breaking out of the loop based upon data being
available on the socket because it may take packets
longer than others to arrive.

There is a success message transferred to the control
connection of the FTP client upon success of the file
transfer. That means that the server has sent all the
packets out... but doesnt mean the client has recieved them
all.

I see my solutions as being setting a boolean variable upon
receipt of the success message from the server... but how
can I tell when the data is done???? Would I need to have a
timeout after an arbitrary amount of time??? Is there any
way to tell that the connection has dropped???
Apparantly the socket is reconnecting on its own after the
completetion of the data transfer... is there a way to set
it to NOT do this????


if you're using a networkstream, try something like this...
// client is a Socket
//Console.WriteLine("Connection accepted...");
ns = new NetworkStream(client);
bool bState, bConnected = true;

while (bConnected)
{
if (ns.DataAvailable) this.GetMessage();
bState = client.Poll(1, SelectMode.SelectRead);

if (bState && client.Available == 0)
bConnected = false;
else
bConnected = true;

System.Threading.Thread.Sleep(100);
}
Nov 15 '05 #3
In article <Xn***************************@65.32.1.8>, Nagash01WS6
wrote:
So... what I think is happening is when the connection is
dropped, the socket reconnects and attempts to continue
reading data. There is no more data.


Traditionally, you detect a socket connection failure by looking for
the receipt of 0 bytes of data.

Hope this helps.

Mike Blake-Knox

Nov 15 '05 #4

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

Similar topics

0
by: Jacob Lee | last post by:
I'm getting a rather bizarre error while using the socket module. If I start out disconnected from the net and then connect while the program or interpreter session is open, I do not always gain...
1
by: Daniel | last post by:
after opening socket, sending data then closing socket 3000 times i get "Only one usage of each socket address" what am i doing wrong? is there some thing else i need to do to free up the socket...
6
by: Robert Mens | last post by:
Hi, I've got this problem with this project i am working on, i am a bit new to c so i don't know why this happens. string is read from a telnet socket. Here's the piece of code that...
2
by: dream machine | last post by:
Hi all, I'm try to check if the one client socket is really connected at my SocketServer . I build Client Socket with BeginAccept() , and I want to receive data with BegenReceive() call ! The...
1
by: Ashwin Kambli | last post by:
Hi, I have a simple socket application. There is a server, and there are many TCP connections to the server. Now, if any one of those connections is lost, is there a way of triggering an event on...
4
by: DaTurk | last post by:
I want to know when a socket disconnects so I can attempt to reconnect. Is there any special type of pattern to doing this? Is there an evnt raised?
0
by: craze3 | last post by:
I have programmed an XML Socket Server to communicate with Flash. It doesn't print out the messages it has received from the flash until the server has been shut down. Any ideas? The part with...
1
by: Miroslav Endys | last post by:
I have two apps. Client and Server (both are windows console apps). Im using Client Socket of this definition AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp and Im using async...
4
by: keithseah | last post by:
Hi all, i've been having this problem and its kiiling me! i'm a newbie at this so i hope someone would be able to help me. picture link:...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...

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.