473,698 Members | 2,440 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 2538
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
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.
4
6730
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
1459
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
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...
14
12773
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
1741
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
3044
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
21408
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
8676
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
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
9161
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...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8867
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4370
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
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.