For my
first real Pharo task I need to communicate with a server over telnet. As a
proof of concept I cobbled this code into a workspace without regard for
OO-anything (the hostname/login/password have been changed to protect the
innocent ;-)
�
| wire
answer |
[
�wire := SocketStream openConnectionToHostNamed: 'myhost'
port: 23.
�[
��wire upToAll: 'login: '.
��wire
nextPutAll: 'testlogin'; cr; flush.
��wire upToAll: 'Password:
'.
��wire nextPutAll: 'dummypassword'; cr;
flush.
��wire upToAll: '>'.
��wire
nextPutAll: 'dbl'; cr; flush.
��wire upToAll:
'?'.
��wire nextPutAll: '12'; cr; flush.
��wire upTo:
Character lf.
��answer := Integer readFromString: (wire
upTo: (Character value: 3)).
��wire upToAll:
'C:\home>'.
��wire nextPutAll: 'exit'. "close
gracefully"
�]
�ensure: [wire close].
�^
answer
]
on: ConnectionClosed
do: [:ex | Transcript show: ex
asString;cr. ex resume].
�
The
server process, dbl, is a simple C program that takes a number, n,�as input
and returns n*2. I'm using character 3 to indicate the end of the output sent
back from the C program.
�
This
all works great and I get the expected answer of '24'.
�
So,
the next step was to simulate the server process taking a while to
complete�and then send back some form of acknowledgement. So I put a 'sleep
5 minutes' in the server process just prior to sending back the answer. The
problem is that I then get a 'ConnectionTimedOut' error after about 45-50
seconds. If I change the 'on:' line to:
�
on:
ConnectionClosed, ConnectionTimedOut
�
then
this errors out with 'IllegalResumeAttempt'.
�
How
can I keep the connection alive while the server is 'busy'?
�
As an
aside, while Pharo is processing the above code, I can't do anything else until
it either completes or errors out. I thought Pharo used 'green
threads'?
�
I'm
using:
�
Pharo-1.1.1--
Latest update:
#11414
�
on
Windows XP Pro.
�
Dan