Is this socket code correct?
Juan Cires Martinez
jcm at mat.upm.es
Fri Nov 19 11:20:52 UTC 1999
The context:
I am trying to control a mobile robot from squeak. I wrote the code for
squeak 2.3 and I'm updating it for 2.6. The mobile robot (or the
simulator) receive commands via sockets with a command/reply type
protocol. This code tries to read the robot's reply after sending a
command. The socket does not close. When the error notifier comes up,
I open the debugger and inspect the value of 'read' and find that it is
zero. I can then manually do a "socket receiveDataInto: buffer" and the
data is read, or I can restart the method and everything continues
working until a while later, when the error notifier comes up again.
I am connecting to a robot simulator running on the same computer as the
squeak system.
Thanks for your help,
Juan.
> [socket dataAvailable] whileFalse:
> [(socket waitForDataUntil: Socket standardDeadline) ifFalse:
> [self error: 'Timeout reading reply']].
> buffer _ ByteArray new: 10000.
> read _ socket receiveDataInto: buffer.
> read < 4
> ifTrue: [self error: 'Too few data read'].
More information about the Squeak-dev
mailing list
|