Re: Console example - WeOnlyDo Discussion board

Re: Console example (General questions)

by Hans, Thursday, January 04, 2007, 17:32 (6531 days ago) @ wodSupport

Kreso,

don't forget that wodSSHServer lives in same thread as your app. At the moment you call gets() you freeze the thread waiting for keyboard input, and you don't allow wodSSHServer to gets its CPU slice to process incoming messages.
Result is that it will accept the connection but will not be able to make any kind of socket communication.

Ok, understood. I can make a loop and use kbhit as non-blocking replacement, but that consumes cpu time.
Since Sleep() also blocks, I searched and found a non-blocking sleep, called Xsleep().
In fact it does the real sleep() in a new thread and waits until the thread is finished while processing the message pump.

The code looks now like:
[code]puts( Starting server );
m_SSHD->Start(var);
puts( Waiting ... press any key to stop the sshserver );
while (!kbhit()) XSleep(300); //check with intervals of 300 millisecs if a key is pressed
m_SSHD->Stop();
[/code]
And it works !! SSH connection with putty works and the application is using almost no cpu time.

Thanks for the support !

Hans


Complete thread: