[Newbies] UDP client-server revisited...

Herbert König herbertkoenig at gmx.net
Thu Dec 3 09:01:46 UTC 2009


Hello Lawson,

Sorry this went private.

LE> Well, trying to get the example code working using class OldSocket.
LE> Doesn't seem to work with squeak or cobalt.

this is a bit unspecific. OldSocket was OldSocket already in a 3.6
image and the class has not a single user (Socket has 84 in a 3.6
image). So I used Socket when I controlled an Asteroids Game via UDP.

LE> I'm stuck trying to figure out how to do it period, and when the 
LE> examples don't work, I'm lost... ;-/

LE> Suggestions? Help?
On this list we had a discussion about this beginning of last month.

I posted the snippet from the end of this message which I tested in
Squeak 3.8 and latest Pharo.

Cheers,

Herbert                            mailto:herbertkoenig at gmx.net

Some code:

Socket initializeNetwork  "Only once per image"
dst := Socket newUDP setPort: 1979.
src := Socket newUDP setPort: 2345.
buff := ByteArray new: 1026.
delay := Delay forMilliseconds: 10.
localhost := ByteArray withAll: { 192. 168. 42. 11 }.
received := nil.

rp := [[ received := dst receiveUDPDataInto: buff.
 received first  isZero ] whileTrue: [ delay wait ].
 WorldState addDeferredUIMessage: [ { buff. received } inspect ]] fork.

src sendUDPData: ( 'ctmame' , (String value: 10) , (String value: 162)) toHost: localhost port:  1979.

rp terminate.
src closeAndDestroy.
dst closeAndDestroy.

src := nil.
dst := nil.
buff := nil.
delay := nil.
rp := nil.

Smalltalk garbageCollect
Socket allInstances



More information about the Beginners mailing list