SocketStream persistence

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

SocketStream persistence

Daniel Klein
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

_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: SocketStream persistence

Daniel Klein
I just discoverd the 'noTimeout' message in the 'configuration' protocol, so that solves my persistence problem.
 
But the question remains: When this process is running, it blocks until it completes. How can I fire it up so that I can continue to interact with Pharo while it is running?
 
Dan


From: [hidden email] [mailto:[hidden email]] On Behalf Of Daniel Klein
Sent: Tuesday, November 09, 2010 22:41
To: 'A friendly place where any question about pharo is welcome'
Subject: [Pharo-users] SocketStream persistence

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

_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
Reply | Threaded
Open this post in threaded view
|

Re: SocketStream persistence

Mariano Martinez Peck


On Wed, Nov 10, 2010 at 3:09 PM, Daniel Klein <[hidden email]> wrote:
I just discoverd the 'noTimeout' message in the 'configuration' protocol, so that solves my persistence problem.
 
But the question remains: When this process is running, it blocks until it completes. How can I fire it up so that I can continue to interact with Pharo while it is running?
 
Dan


From: [hidden email] [mailto:[hidden email]] On Behalf Of Daniel Klein
Sent: Tuesday, November 09, 2010 22:41
To: 'A friendly place where any question about pharo is welcome'
Subject: [Pharo-users] SocketStream persistence

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

_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users



_______________________________________________
Pharo-users mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users