Archived Forum Post

Index of archived forum posts

Question:

Failed to receive data on the TCP socket

Nov 20 '15 at 09:19
    ChilkatLog:    
        Connect_SFtp:      
            DllDate: May  8 2015      
            ChilkatVersion: 9.5.0.49

UnlockPrefix: ***

Username:
* Architecture: Little Endian; 32-bit

Language: .NET 2.0
VerboseLogging: 0
SftpVersion: 0
hostname:
**** port: 22
sshConnect:
Established TCP/IP connection with SSH server
clientIdentifier: SSH-2.0-PuTTY_Release_0.63
Sending client identifier...
Done sending client identifier.
Reading server version...
WindowsError: An established connection was aborted by the software in your host machine.
WindowsErrorCode: 0x2745
numBytesRequested: 1
Failed to receive data on the TCP socket
Failed to read initial server version string
bytesReceived:
--sshConnect Failed.
--Connect_SFtp
--ChilkatLog


Answer

This error:

WindowsError: An established connection was aborted by the software in your host machine.
WindowsErrorCode: 0x2745 

Is caused by the following sequence of events, which could apply to any protocol (SMTP, HTTP, IMAP, FTP, SSH, SFTP, etc.)

  1. The client sends something to the server.
  2. The server dislikes what it receives, for whatever reason, and decides to close the connection.
  3. The client then attempts to read the connection -- and it finds the connection has already been closed. Thus the message ("An established connection was aborted by the software in your host machine.")

When the server decided to close the connection, the its TCP "close" socket operation results in a "FIN" segment being sent to its peer (the client). The Windows OS receives it and thus the connection becomes closed. The next time the application tries to read/write the connection, it finds it's already been closed.

To debug a problem such as this, the question becomes: "What was wrong with the last message sent to the server? Was it properly formatted (i.e. was the client software working correctly?), or was the message formatted properly, but the contents of the message were unacceptable?" With Chilkat, it is far more likely that the latter is the cause.

One way to find out why the SSH server is closing the connection, is to run the SSH server with verbose/debug logging, and run it interactively for the test. For example, assuming the SSH server is on a Linux box, go to that box and stop the SSH server ("sudo kill -9 <pid>")

Then start sshd interactively as shown below. You may have to give the full path to the sshd..

sudo /home/chilkat/openssh-7.1p1/sshd -Dde

You should see verbose/debug logging from sshd emitted to the output. Then run your app. You should see the sshd receive the connection -- and if it dislikes something, you should see the sshd's debug logging to the stdout giving some details as to why it disconnects the client.