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 _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Hi Andy,
AB> That's great, thank you very much. I have a couple of other AB> questions that sprang from using this code. AB> 1. I couldn't get the WorldState addDeferredUIMessage: to do AB> anything. What is supposed to happen? I am running the latest AB> Pharo build. The class exists, and I didn't get a DNU, but I AB> didn't get anything else either! uh yeah I wasn't sure what approach you would choose and I was about to leave for work. Sorry. First I'm on Squeak 3.8 so let me try Pharo. All works fine in what I just downloaded from Pharo Website. So, after you added the deferred UI message, the next line (sendUDPData...) should pop up an Inspector with an Array. I found the deferred UI message trick somewhere in the archives or maybe got direct help from someone. You won't need it. You need two images. In the receiver you build a loop in which you do something like: commSocket dataAvailable ifTrue: [receiveResult := commSocket receiveUDPDataInto: receiveBuffer. "now display your time in a big TextMorph"] ifFalse: [myDelay wait] Doing real time asynchronous things with the Squeak UI is a bit tricky but following the lead of ClockMorph should get you going. The common animation methods in Squeak isolate you from that problems but changing a Morph's shape at the wrong moment is not good. Sorry I can't be more specific but if you report problems I will remember them, I did several animations of lots of Morphs. AB> 2. Out of curiosity, I tried used the NetNameResolver AB> addressForName: method as a way of getting a socket address AB> (instead of using the ByteArray. I tried this when nothing was AB> working, and I noticed the method call in several of the Socket AB> methods. However, Squeak gave me a DNU. Is there a simple way to AB> enter host names using the NetNameResolver, or have I completely AB> misunderstood its function? no, you haven't. I used the code in a network with fixed IP's and no DHCP running. Right here using NetNameResolver works just fine. If you doIt: (NetNameResolver addressForName: 'aComputersName') inspect you should get an Inspector on a ByteArray with the IP address. Cheers, Herbert _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Andy Burnett
David Corking said <<
Thanks David, I have never heard of the Nebraska system. It looks very interesting. I will have a go with it. Cheers Andy _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Andy Burnett
Herbert said <<
no, you haven't. I used the code in a network with fixed IP's and no DHCP running. Right here using NetNameResolver works just fine. If you doIt: (NetNameResolver addressForName: 'aComputersName') inspect you should get an Inspector on a ByteArray with the IP address. >> Hmmm, I was expecting to get an inspector on a ByteArray, but what I actually got was an inspector on SocketAddress. Something is obviously not quite right here! :-) _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Hi Andy,
AB> (NetNameResolver addressForName: 'aComputersName') inspect AB> you should get an Inspector on a ByteArray with the IP address. AB> Hmmm, I was expecting to get an inspector on a ByteArray, but AB> what I actually got was an inspector on SocketAddress. Something AB> is obviously not quite right here! :-) again not on your side, I tried in Pharo and they introduced a class SocketAddress. You have to send that instance the message hostNumber to get the IP-Address as .... oops ... a String. I surely didn't expect that! What makes it worse, is that my code works though I hand an Array as the IP address to Socket. So my best guess is you go to the Pharo list and ask about the proper way to set up a UDP (or TCP) connection. I could tell you how to pick the bytes out of SocketAddress but this is Smalltalk after all. There must be a high level way. Sorry for no better reply, Herbert _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |