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

Socket Disconnect

I built a very basic server-client in C#. When my server disconnects
from the client, the socket at the server is already disconnected, but
the socket the client remains open. I used the sample code in .Net's
documentation to disconnect:

socket.Shutdown( SocketShutdown.Both );
socket.Disconnect( false );

I also tried

socket.Close() instead of Disconnect.

I compiled my code with MS Studio 2005. When I used to compile it
with MS Studio 2003, it worked just fine.

Anybody had the same problem? Thanks.

Mar 3 '07 #1
3 2541
On 3 Mar 2007 14:58:32 -0800, xi****@yahoo.com wrote:
>I built a very basic server-client in C#. When my server disconnects
from the client, the socket at the server is already disconnected, but
the socket the client remains open. I used the sample code in .Net's
documentation to disconnect:

socket.Shutdown( SocketShutdown.Both );
socket.Disconnect( false );

I also tried

socket.Close() instead of Disconnect.

I compiled my code with MS Studio 2005. When I used to compile it
with MS Studio 2003, it worked just fine.

Anybody had the same problem? Thanks.
Is the client connecting through a switch or a router? I believe they
can hold onto a connection for a period of time. At least that is
what I suspect from problems I have in trying to work out
connection/disconnection issues.
Mar 3 '07 #2
On Mar 3, 3:25 pm, r norman <r_s_norman@_comcast.netwrote:
On 3 Mar 2007 14:58:32 -0800, xin...@yahoo.com wrote:
I built a very basic server-client in C#. When my server disconnects
from the client, the socket at the server is already disconnected, but
the socket the client remains open. I used the sample code in .Net's
documentation to disconnect:
socket.Shutdown( SocketShutdown.Both );
socket.Disconnect( false );
I also tried
socket.Close() instead of Disconnect.
I compiled my code with MS Studio 2005. When I used to compile it
with MS Studio 2003, it worked just fine.
Anybody had the same problem? Thanks.

Is the client connecting through a switch or a router? I believe they
can hold onto a connection for a period of time. At least that is
what I suspect from problems I have in trying to work out
connection/disconnection issues.
Both the client and server are on the same machine. It is for testing
purpose.
The thing which confuses most is that after the server has
disconnected, the client still tries to call the socket.Send function,
it went through without any error.
Mar 3 '07 #3
On Mar 3, 3:32 pm, xin...@yahoo.com wrote:
On Mar 3, 3:25 pm, r norman <r_s_norman@_comcast.netwrote:
On 3 Mar 2007 14:58:32 -0800, xin...@yahoo.com wrote:
>I built a very basic server-client in C#. When my server disconnects
>from the client, the socket at the server is already disconnected, but
>the socket the client remains open. I used the sample code in .Net's
>documentation to disconnect:
>socket.Shutdown( SocketShutdown.Both );
>socket.Disconnect( false );
>I also tried
>socket.Close() instead of Disconnect.
>I compiled my code with MS Studio 2005. When I used to compile it
>with MS Studio 2003, it worked just fine.
>Anybody had the same problem? Thanks.
Is the client connecting through a switch or a router? I believe they
can hold onto a connection for a period of time. At least that is
what I suspect from problems I have in trying to work out
connection/disconnection issues.

Both the client and server are on the same machine. It is for testing
purpose.
The thing which confuses most is that after the server has
disconnected, the client still tries to call the socket.Send function,
it went through without any error.
I found the problem. Disconnect fails when there's no traffic between
the server and the client.
Make sure you send a 1 byte message when you want to test for
connection. Calling Send with 0 byte messages won't work.
Mar 4 '07 #4

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

Similar topics

4
by: DreJoh | last post by:
I've read many articles on the subject and the majority of them give the same solution that's in article 821625 on the MSDN website. I'm using the following code and when a the client disconnects...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
0
by: integragreg | last post by:
I apologize in advance if I am posting to the wrong group, but at least one of my questions is related to Platform Invoke in C#. I am using .NET Framework 1.1, and for improved performance, I...
3
by: HABJAN ®iga | last post by:
Is there a way to be notifyed (callback, event,...) when the connection of socket was closed... The WinSock activex in vb6 had event ondisconnect... I get exception when i try to send some data,...
1
by: Jay | last post by:
I have a client app sending messages over the socket on a certain port. In the client app: I do this for every message I need to send: 1. Create a socket and connect. 2. Send message 3. Close...
11
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling...
3
by: Cheryl | last post by:
Hi. I am having a problem on handling asynchronous sockets in C#. I implemented a pair of client and server sockets. The connection is ok when first connected. However, when I turned off the...
4
by: Adam Clauss | last post by:
A while back I posted regarding a problem we were having with one of our applications which was randomly crashing. Monitoring memory usage revealed a spike in nonpaged pool memory just prior to...
21
by: puzzlecracker | last post by:
Problem: I send a lot of requests to the application (running on a different box, of course), and I receive back responses from the app . Below: socket corresponds to Socket socket=new...
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
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: 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.