473,698 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Disconne ct( 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 2578
On 3 Mar 2007 14:58:32 -0800, xi****@yahoo.co m 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
documentatio n to disconnect:

socket.Shutdow n( SocketShutdown. Both );
socket.Disconn ect( 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@_co mcast.netwrote:
On 3 Mar 2007 14:58:32 -0800, xin...@yahoo.co m 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.Disconne ct( 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.co m wrote:
On Mar 3, 3:25 pm, r norman <r_s_norman@_co mcast.netwrote:
On 3 Mar 2007 14:58:32 -0800, xin...@yahoo.co m 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
>documentatio n to disconnect:
>socket.Shutdow n( SocketShutdown. Both );
>socket.Disconn ect( 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
8726
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 the child socket remains in the CLOSE_WAIT state. Anyone have any idea what's missing? ----------------------------- Socket Code ----------------------------- namespace Sockets { #region Class - SocketClient
4
18120
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 as I find appropriate. I am using the socket asynchronously by calling the BeingSend and BeginReceive calls. I would like to be able to call shutdown and close asynchronously if possible.
0
4064
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 need to be able to reuse a client socket by placing it into a pool. Unfortunately, with .NET Framework 1.1 I have no way to close a socket's connection to a remote host without disposing of the socket's resources altogether (i.e, Socket.Close()),...
3
1829
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, but i need disconnect info sooner. I have a solution with timer that checks the state of socket, but i don't like to use timers... best re,
1
6371
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 socket. The Listener requires that the client keep the socket connected while sending messages..which is every 20-30 seconds. My question is: Can I keep the connection open for the whole day? Connect
11
8602
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 mechanisms. I use a non-blocking approach for this, using the call to 'poll' to support the async mechanism - rather than the 'begin' and 'end' functions. I already found that connecting doesn't set the "isconnected" variable correctly...
3
14413
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 server socket, the client is able to connect, but cannot send anything out. It seems that the Socket.Connected is false but I received no disconnection event. Any idea on how to solve the problem? Thanks.
4
4308
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 the crash each time. We finally think we have narrowed down the cause of this to a user (located semi-remotely) who would connect into our system and disconnect "ungracefully" (literally, by pulling his network cable). Connections here are all...
21
5659
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 Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
0
8612
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8905
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7743
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4373
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
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
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.