[Newbies] Building a remote count down clock

Herbert König herbertkoenig at gmx.net
Fri Nov 6 06:46:35 UTC 2009


Hi Andy,

AB> My initial thought was to do it in seaside. However, I then
AB> wondered whether it would be better to build it all in Squeak. 
AB> The benefit of the Squeak approach (I am guessing) is that I could
AB> somehow broadcast to the listening images that I wanted them to
AB> start/stop, rather than have them polling every second. Obviously,
AB> the app is tiny, so in practical terms it doesn't matter either
AB> way, but I am now curious about how I might communicate the
AB> start/stop messages over the network to the images.  Is this
AB> relatively easy in Squeak?

at the end of this message you'll find a copy of a workspace which I
used to test network communication. I can help out with more code.

I have no knowledge about Seaside but in AidaWeb a real time clock is
part of the demos. Basically the Browser updates parts of the page via
Ajax. Dunno how stable that is (Browser side), if it runs for hours.

In class Socket you'll also find TCP communication, I used UDP
because I controlled an Asteroids game at a frame rate of 50 per
second. TCP will make sure the packet is received or notify the
sender, with UDP you have to make sure yourself.

Can't help you with broadcasts (I guess it's a matter of the address
you send to) but there you definitely will have no knowledge if your
data was received.



-- 
Cheers,

Herbert

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