Urgent problem with An existing connection was forcibly closed by the remote host  
Author Message
Linda Shao





PostPosted: .NET Framework Networking and Communication, Urgent problem with An existing connection was forcibly closed by the remote host Top

Hi,

I have an urgent problem need help. We have an Asp.net application runing on window 2003 server. One part of the application is socket programming. When customer hits our site a little bit heavier, after serveral thoudsands hits, I statrt to get a bunch of

An existing connection was forcibly closed by the remote host

exceptions, then if the customer continue hits the site, the other function throw out of memory exception, The result is our site not responding any more. The attached is the socket call programming, any help will be appreciated! Thank you.

IPAddress[] ips = Dns.GetHostAddresses(m_sAVSHost);
IPEndPoint oIPEndPoint = new IPEndPoint(ips[0], iAvsPort);
Socket oSocket = new Socket(oIPEndPoint.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
try
{
oSocket.Connect(oIPEndPoint);
byte[] bSendBytes = Encoding.UTF8.GetBytes(sAvsParam);
oSocket.Send(bSendBytes, bSendBytes.Length, SocketFlags.None);

byte[] bRecvBytes = new byte[4096];
oSocket.Receive(bRecvBytes, SocketFlags.None);
rtnVal = Encoding.UTF8.GetString(bRecvBytes).Trim();
}
catch (Exception ex)
{
VVXmlListenerException.LogException(new VVXmlListenerException(ex));
}
finally
{
oSocket.Shutdown(SocketShutdown.Both);
oSocket.Close();
}



.NET Development25  
 
 
IanG





PostPosted: .NET Framework Networking and Communication, Urgent problem with An existing connection was forcibly closed by the remote host Top

I would run a packet trace to find out what's actually going over the network. (Use a tool like Ethereal or Netmon.)

On all the occasions I've seen this exception, it has meant exactly what it says: the connection was forcibly closed. So this suggests that whatever your code here is connecting to is closing the connection. (Or you're going through a firewall, proxy, or other intermediary which is closing it.) The first step would be to confirm that - look at the actual packets going across the network to see what's really happening - that will most likely confirm that the error you're getting is consistent with the incoming network packets.

And if that's what you see, then the problem is external to the code you're showing us here. You need to look into why the external system - the thing that this code connects to - is kicking you off.

What does this code connect to (I.e. what is m_sAVSHost )


 
 
Mariya Atanasova - MSFT





PostPosted: .NET Framework Networking and Communication, Urgent problem with An existing connection was forcibly closed by the remote host Top

For instructions on how to get a netmon trace see here:
For instructions on how to get a System.Net tracing log go here:
Mariya

 
 
Malar Chinnusamy





PostPosted: .NET Framework Networking and Communication, Urgent problem with An existing connection was forcibly closed by the remote host Top

I guess this is because the number of clients exceed the backlog set in the listen request of the server.

Please take a look at (5) & (6) th points in

https://blogs.msdn.com/malarch/archive/2006/06/26/647993.aspx.

Try to avoid starting many clients at the same time.. One simple solution is to Add a random sleep before starting the clients.

Malar


 
 
Mariya Atanasova - MSFT





PostPosted: .NET Framework Networking and Communication, Urgent problem with An existing connection was forcibly closed by the remote host Top

Customer now resends the data when the other side closes the connection

Mariya


 
 
huseyin_





PostPosted: .NET Framework Networking and Communication, Urgent problem with An existing connection was forcibly closed by the remote host Top

I am living diffuculty at the same problem if you have solved the problem can you help me please Thank you in advance