Skip to content

Instantly share code, notes, and snippets.

@seandenigris
Created December 8, 2012 23:01
Show Gist options
  • Save seandenigris/4242432 to your computer and use it in GitHub Desktop.
Save seandenigris/4242432 to your computer and use it in GitHub Desktop.
Pharo Smalltalk TCP Server
"Adapted from http://www.slideshare.net/nourybouraqadi/pharo-networking-by-example
$! denotes the end of a message
"
| connectionSock interactSock request stream |
connectionSock := Socket newTCP.
[
connectionSock listenOn: 8888 backlogSize: 10.
interactSock := connectionSock waitForAcceptFor: 15.
stream := SocketStream on: interactSock.
request := stream upTo: $!.
stream sendCommand: 'Pharo Server: ', request, ' received!'.
Transcript cr; show: request.
] ensure: [
connectionSock closeAndDestroy.
stream close ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment