C# an Established Connection Was Aborted by the Software in Your Host MAChine

C# An established connection was aborted by the software in your host machine

An established connection was aborted by the software in your host machine

That is a boiler-plate error message, it comes out of Windows. The underlying error code is WSAECONNABORTED. Which really doesn't mean more than "connection was aborted". You have to be a bit careful about the "your host machine" part of the phrase. In the vast majority of Windows application programs, it is indeed the host that the desktop app is connected to that aborted the connection. Usually a server somewhere else.

The roles are reversed however when you implement your own server. Now you need to read the error message as "aborted by the application at the other end of the wire". Which is of course not uncommon when you implement a server, client programs that use your server are not unlikely to abort a connection for whatever reason. It can mean that a fire-wall or a proxy terminated the connection but that's not very likely since they typically would not allow the connection to be established in the first place.

You don't really know why a connection was aborted unless you have insight what is going on at the other end of the wire. That's of course hard to come by. If your server is reachable through the Internet then don't discount the possibility that you are being probed by a port scanner. Or your customers, looking for a game cheat.

C# - an established connection was aborted by the software in your host machine Error

Setting the correct Content-Length fixed it.

If Content-Length is greater than the actual length, the client-side will continue to wait for the remaining parts of the response. But since the server is already done with sending the response, it will end the process.

An established connection was aborted by the software in host machine

Probably because you're breaking the while loop (look my comment)

while (true)
{
Socket handler = listener.Accept();
data = null;

while (true)
{
bytes = new byte[1024];
int bytesRec = handler.Receive(bytes);

data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
TextRecieved = data;
Thread textbox = new Thread(new ThreadStart(WriteInReachTextBox));
textbox.Start();

// -----------> HERE!!!!!!

break;
}

//uirtbreport.Text = data;
byte[] msg = Encoding.ASCII.GetBytes(data);
handler.Send(msg);
handler.Shutdown(SocketShutdown.Both);
handler.Close();
}

Why do you create a thread within the 'broken' loop?

Also, don't forget this is a streaming socket, which means that 'packets' can be sent as one buffer or split into multiple 'packets'.

An established connection was aborted by the software in your host machine

You're probably hitting a timeout. First of all, turn the keepalive back on. Second, check the timestamps on the request and reply. If there is a firewall between the sender and receiver, make sure that it isn't closing the connection because of idle timeout. I've had both these problems in the past, although with generic socket programming, not DB stuff.



Related Topics



Leave a reply



Submit