EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Issue with ElSimpleSSHClient.CanReceive

Posted: 11/03/2010 12:04:12
by Jamie Otterstetter (Standard support level)
Joined: 11/03/2010
Posts: 7

Hello, I'm getting an exception when I attempt to use ElSimpleSSHClient.CanReceive. This is the exception:

Exception class EElSocketError with message "Wrong socket state 0 in CanReceive (error code is 96258)"

Here is a snippet of my code, the exception is coming out of ElSocket.CanReceive with is ultimately called by ElSimpleSSHClient.CanReceive.

if (MyTElSimpleSSHClient->Active) {

MyTElSimpleSSHClient->Command = "grep xyz /abc/somefile";

if (MyTElSimpleSSHClient->Active && MyTElSimpleSSHClient->CanReceive(2000)) {
//do something

If the "Command" doesn't return anything (in this case a "grep" that doesn't find anything) then CanReceive always throws an exception instead of returning false, if grep finds something then there is no issue and things work as expected. Is this expected? If so, what type of exception should I be trying to catch? I don't see any exception types in the docs.

Posted: 11/03/2010 12:28:00
by Eugene Mayevski (Team)

Thank you for contacting us.

1) what version of SecureBlackbox are you using?
2) the error message is talking about socket's CanReceive which can be called from Open, not necessarily from your further call. I.e. please check if execution passes past a call to Open().

3) Please change your code to

while (MyTElSimpleSSHClient->Active || MyTElSimpleSSHClient->CanReceive(0))
  if (MyTElSimpleSSHClient->CanReceive(2000) {
    // Receive the data

Sincerely yours
Eugene Mayevski
Posted: 11/03/2010 12:29:15
by Vsevolod Ievgiienko (Team)


96258 (0x17802 in HEX) is the socket error which means "connection was lost". This means that the server has forcefully closed connection after the command returned no data.
Posted: 11/03/2010 13:04:58
by Jamie Otterstetter (Standard support level)
Joined: 11/03/2010
Posts: 7

Hello Eugene, I'm using version 8.1.190, and it's definitely coming out of the CanReceive, I've verified that with breakpoints. I put in your changes but I still see the exception. I noticed that if I change the second CanReceive (in the "if") to use a 0 timeout (instead of 2000) the exception goes away, but I'm not sure if that is safe or not, of if that is just luck based on some random timing.
Posted: 11/03/2010 13:18:52
by Eugene Mayevski (Team)

Got it. It's the normal situation in your particular case. The socket itself doesn't know that connection has been dropped until you attempt to use it. This is what happens - the last operation was performed in Open method and then the socket was connected (Active remains true). Now CanReceive sees that there's no data in the internal buffer and asks the socket if the socket has data to retrieve. But the socket neither has data nor can receive them (because the server has closed connection after Open and before CanReceive). So the exception is reported.

So you need to wrap the code with try/catch and that's all.

We will discuss with developers whether we can handle the exception internally in ElSimpleSSHClient. While this would seem logical, the change in code would introduce a change in behavior and some existing user code might become broken. So wrapping the code with try/catch seems to be optimal in your case.

Sincerely yours
Eugene Mayevski
Posted: 11/04/2010 17:56:18
by Jamie Otterstetter (Standard support level)
Joined: 11/03/2010
Posts: 7

After some experimentation it appears that using "ExecuteCommand" does what I need, if there is no data to be sent back I just get an empty string and no exception. On that note, is there a way to get the return code from the command that I ran with "ExecuteCommand", ie if my command was some type of script with a return code?

Posted: 11/05/2010 02:11:30
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 442

Hi. You should check the ExitStatus property.



Topic viewed 2132 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!