[Newbies] UDP client-server revisited...
Lawson English
lenglish5 at cox.net
Thu Dec 3 14:04:31 UTC 2009
Thanks very much. Sorta got things almost working, but still confused
abut threading/forking/non-blocking issues (2-year programming degrees
don't go into the multi-processing stuff so I'm supplementing with
online lectures from MIT, arsdigita, etc. Feedback isn't a forte with
passive web lectures however).
I've new hurdles to get over, including the non-blocking design, and how
to make sure my packed stream method doesn't pad my UDP packets with
zeros at the end but that latter is purely a mechanical detail to trace
through.
Thanks again.
Lawson
Herbert König wrote:
> 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
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
>
More information about the Beginners
mailing list