’From Smalltalk 5.5bXM July 4 on 8 August 1979 at 2:50:47 pm.’ ̃
"EchoServer"
Class new title: ’EchoServer’
subclassof: Socket
fields: ’in out’
declare: ’’;
asFollows̃

An Echo Server merely sits listening on a well-known socket,
bouncing echo requests back to the source.
This is a sub-class of socket, with a specialized way to process an input

Initialization
init "Start listening on socket 5"
[
in ← out ← 0.
self from: (Int32 new high: 0 low: 5).
]

Handle Input
socProcess: Ipac | tempPort "Overwrite from def. of regular socket"
[
"we are running at a higher level ......"
in ← in + 1.
Ipac pupType = 1 
[
Ipac pupType ← 2.
Ipac swapPorts.
self completePup: Ipac.
out ← out+1.
]
"got something really funny"
self freePacket: Ipac
]

Statistics
in [ffiin]
out [ffiout]
printon: strm
[
strm cr.
strm append: ’Echo server, ’.
in printon: strm.
strm append: ’ in and ’.
out printon: strm.
strm append: ’ out.’
]
reset [in←out←0]
̃
SystemOrganization classify:  EchoServer under: ’Ethernet Control’.̃

"EchoUser"
Class new title: ’EchoUser’
subclassof: Socket
fields: ’ID out in inGood inBad’
declare: ’’;
asFollows̃

This class has not yet been commented

Initialization
net: net host: host
[
ID← Int32 new high: 0 low: 0.
in←inGood ← inBad←out←0.
self net: net host: host soc: (Int32 new high: 0 low: 5).
]

Handle Input
socProcess: Ipac | i "Overwrite from def. of regular socket"
[
"got some sort of answer"
in←in+1.
i ← Ipac pupType.
[i = 2  [inGood←inGood+1 ]].
[i = 3  [inBad ← inBad + 1 ]].
self freePacket: Ipac.
]

Handle Output
send | pac "short comment"
["long comment if necessary"
pac ← self freePacket
[
out←out+1.
pac pupID← ID← ID+(Int32 new high: 0 low: 1).
pac pupType ← 1.
pac dataString ← ’’.
self setAddressesAndComplete: pac.
self freePacket: pac.
]
user show: ’freeQ empty, in Echo User’
]

Statistics
printon: strm
[
strm cr.
strm append: ’Echo user, ’.
out printon: strm.
strm append: ’ out; received ’.
in printon: strm.
strm append: ’ in / ’.
inGood printon: strm.
strm append: ’ OK / ’.
inBad printon: strm.
strm append: ’ not OK.’.
]
reset [in←inGood←inBad←out←0]
̃
SystemOrganization classify:  EchoUser under: ’Ethernet Control’.̃