1

Here was a ssh server at My win10, than When I ran the demo named example-ssh2 builded by visual studio 2015 from libssh2 1.90. I saw the tcp socket was ESTABLISHED.

session = libssh2_session_init()

was successed.But

libssh2_session_handshake(session, sock)

always return -43.

Could you help me?

sculida
  • 11
  • 3

1 Answers1

1

I was getting this -43 when connecting to servers on high latency networks.

Libssh2.h has this definition...

define LIBSSH2_ERROR_SOCKET_RECV -43

I was able successfully connect consistently by adding a short sleep between the libssh2_session_init() call and the libssh2_session_handshake(session, sock) call like this...

session = libssh2_session_init();
std::this_thread::sleep_for(std::chrono::milliseconds(300));
libssh2_session_handshake(session, sock);

I chanced upon this solution by single stepping over the original code in the debugger, and it would successfully connect every time, so I tried the sleep and it worked. I tried some different sleep times, with 30ms being the lowest value that still worked.

I found your post while trying to find an explanation for this behavior. I hope this method works for you.

Community
  • 1
  • 1
bernieweir
  • 11
  • 2