473,396 Members | 2,010 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,396 software developers and data experts.

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 2523
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.btinternet.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.btinternet.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(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
s.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeout, 30000); s.Connect(ipe);
writeToSocket(s, ipe, "1");
writeToSocket(s, ipe, "2");
writeToSocket(s, ipe, "3");
s.Shutdown(SocketShutdown.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.btinternet.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
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...
4
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
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...
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...
14
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...
0
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...
3
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);...
1
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...
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: 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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
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...
0
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,...

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.