473,732 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Client Socket lingering after close

Hi Guys,
I'm sorry if you have heard this one before but searching the net
hasn't found a solution.

I am using Socket in a client to connect to a server. However, after
I've finished sending and recieving data and call the Close() method the
socket lingers for a couple of minutes. This is demonstrated by using
netstat -a.

I've tried an assortment of SocketOptions (Linger, and DontLinger), but
all with no success.

Is there a definitive answer for the lingering socket? Is it an OS
problem (I am running XP Home), Is it a .Net Framework bug? What do I do
to close connection?

Thanks in advance
James.
Nov 17 '05 #1
3 2541
Just a hunch.
If your scenario permits, Have you tried closing the connection from server?

HTH
rawCoder

"Jimbo" <ji***@notexist .domain.com> wrote in message
news:d2******** **@titan.btinte rnet.com...
Hi Guys,
I'm sorry if you have heard this one before but searching the net
hasn't found a solution.

I am using Socket in a client to connect to a server. However, after
I've finished sending and recieving data and call the Close() method the
socket lingers for a couple of minutes. This is demonstrated by using
netstat -a.

I've tried an assortment of SocketOptions (Linger, and DontLinger), but
all with no success.

Is there a definitive answer for the lingering socket? Is it an OS
problem (I am running XP Home), Is it a .Net Framework bug? What do I do
to close connection?

Thanks in advance
James.

Nov 17 '05 #2
Unfortunately no. My client is calling web services on various different
servers.

Just one addition, I am also using the Shutdown method on the Socket :-)

James.

rawCoder wrote:
Just a hunch.
If your scenario permits, Have you tried closing the connection from server?

HTH
rawCoder

"Jimbo" <ji***@notexist .domain.com> wrote in message
news:d2******** **@titan.btinte rnet.com...
Hi Guys,
I'm sorry if you have heard this one before but searching the net
hasn't found a solution.

I am using Socket in a client to connect to a server. However, after
I've finished sending and recieving data and call the Close() method the
socket lingers for a couple of minutes. This is demonstrated by using
netstat -a.

I've tried an assortment of SocketOptions (Linger, and DontLinger), but
all with no success.

Is there a definitive answer for the lingering socket? Is it an OS
problem (I am running XP Home), Is it a .Net Framework bug? What do I do
to close connection?

Thanks in advance
James.


Nov 17 '05 #3
Small update. I haven't solved the problem of lingering sockets. However
a bit of re-architecturing means that I now reuse sockets rather than
creating new ones. I now have one socket per server/port and use the
send and recieve functions on that socket.

The simplified code below shows this in action:

IPAddress ipa = IPAddress.Parse ("192.168.0.10" );
IPEndPoint ipe = new IPEndPoint(ipa, 80);
Socket s = new Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
ProtocolType.Tc p);
s.SetSocketOpti on(SocketOption Level.Socket,
SocketOptionNam e.ReceiveTimeou t, 30000); s.Connect(ipe);
writeToSocket(s , ipe, "1");
writeToSocket(s , ipe, "2");
writeToSocket(s , ipe, "3");
s.Shutdown(Sock etShutdown.Both );
s.Close();
Where writeToSocket contains my code for sending the data down the
socket and waiting for a response.

If anyone does solve the lingering socket problem then let me know.

Cheers
James.

Jimbo wrote:
Unfortunately no. My client is calling web services on various different
servers.
rawCoder wrote:
Just a hunch.
If your scenario permits, Have you tried closing the connection from
server?

"Jimbo" <ji***@notexist .domain.com> wrote in message
news:d2******** **@titan.btinte rnet.com...
Hi Guys,
I'm sorry if you have heard this one before but searching the net
hasn't found a solution.

I am using Socket in a client to connect to a server. However, after
I've finished sending and recieving data and call the Close() method the
socket lingers for a couple of minutes. This is demonstrated by using
netstat -a.

Nov 17 '05 #4

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

Similar topics

4
18130
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.
4
6735
by: rs | last post by:
how I the client tell the server that the socket is closed? or this there an even that informs the server that the clients socket is close? Oh, I am using vb.net 2003 Thanks
0
1462
by: Usman | last post by:
Hi I'm having problem with a scenarion where I have a server written in C# and client written in VC6++. Here is the server code that i'm using including the Callback function for handling clients. Also there's a commented code where i'm using TCPListener instead of simple Socket Class. The problem i'm having is that when I run this code using Socket class, the server starts well but "OnClientConnect" method never gets called. On...
11
8610
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...
14
12790
by: ahlongxp | last post by:
Hi, everyone, I'm implementing a simple client/server protocol. Now I've got a situation: client will send server command,header paires and optionally body. server checks headers and decides whether to accept(read) the body. if server decided to throw(dump) the request's body, it'll send back a response message, such as "resource already exists" and close the connection.
0
1746
by: khu84 | last post by:
Here is client server very simple code, seems to work with telnet but with with web client code gives blank output. Following is the server code:- <?php function createSocketServer($host='192.168.1.34',$port=2222) { $max_clients = 10;
3
3052
by: A. W. Dunstan | last post by:
I'm creating a socket as follows: m_networkSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); m_networkSocket.LingerState = new LingerOption(true, 1); m_networkSocket.Blocking = true; m_networkSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true); m_networkSocket.SetSocketOption(SocketOptionLevel.Socket,
1
21413
by: diegoblin | last post by:
Hi, i kind of new to java and i want to transfer a file between a server and a client. I know i have to use InputStream and OutputStream, but i don't know how to do it properly. So far i think i've managed to do the client part. i read the content of a file, "hi.txt", and i send it to the server. The problem is in the server part, i do not know how to write the file in the server. Thanks in advance for your help Here is my code for the...
0
8774
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,...
0
9447
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9235
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
8186
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
6735
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
6031
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
4550
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...
1
3261
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
2721
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.