[Newbies] Re: Building a remote countdown clock
Andy Burnett
andy.burnett at knowinnovation.com
Fri Nov 6 21:46:38 UTC 2009
Herbert said
<<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>>
That's great, thank you very much. I have a couple of other questions that
sprang from using this code.
1. I couldn't get the WorldState addDeferredUIMessage: to do anything. What
is supposed to happen? I am running the latest Pharo build. The class
exists, and I didn't get a DNU, but I didn't get anything else either!
2. Out of curiosity, I tried used the NetNameResolver addressForName: method
as a way of getting a socket address (instead of using the ByteArray. I
tried this when nothing was working, and I noticed the method call in
several of the Socket methods. However, Squeak gave me a DNU. Is there a
simple way to enter host names using the NetNameResolver, or have I
completely misunderstood its function?
Cheers
Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20091106/fb6678ad/attachment.htm
More information about the Beginners
mailing list