Squeak networking overview ?
Chris Muller
chris at funkyobjects.org
Fri Aug 5 14:39:38 UTC 2005
> * Is there a Squeak networking overview anywhere ?
> * Also,
> i'm having trouble getting the basic Socket examples to work.
Hi Orion, I'm not sure about the Socket examples in the image, but another
simple example (for client-server style) that I sometimes use as a sanity check
that the network is working.
You must load "Ma client server" from SqueakMap. It has two simple classes
that wrap a Squeak standard Socket. The scripts below demonstrate sending and
receiving bytes between both images.
"Inspect in the server image, when done execute 'self shutdown'"
| serverSocket |
serverSocket _ MaServerSocket new server: MaTranscriptConsole new.
serverSocket
listenOn: 1010
answer:
[ :requestByteArray | requestByteArray reverse ].
serverSocket
"Open a transcript in client image and run this:"
| mySocket requestByteArray response eachResponse randomStream
byteArrayRandomizer requestSize serverIp largestTest |
largestTest _ 9000.
randomStream _ Random new.
response _ ByteArray new: 4000. "<- purposely too small"
requestByteArray _ ByteArray new: largestTest.
byteArrayRandomizer _
[ :size |
1 to: size do:
[ :index | requestByteArray at: index put: (randomStream nextInt: 256) - 1 ]
].
serverIp _ FillInTheBlank
request: 'Enter the IP of the host:'
initialAnswer: '127.0.0.1'.
mySocket _ MaClientSocket
hostAddress: (NetNameResolver addressFromString: serverIp)
port: 1010.
1 to: 500 do:
[ :count |
requestSize _ (randomStream nextInt: largestTest).
byteArrayRandomizer value: requestSize.
eachResponse _ mySocket
sendData: requestByteArray
startingAt: 1
count: requestSize
waitForReplyIn: response.
(requestByteArray copyFrom: 1 to: requestSize) reverse = (eachResponse
copyFrom: 1 to: requestSize) ifFalse: [ self halt ].
Transcript cr; show: count printString, ' successful conversations.' ]
More information about the Squeak-dev
mailing list
|