Hilaire, All this is quite tricky and can be platform dependent. What works for me (non-broadcast) is the following Pharo code for listening: socket := Socket newUDP setPort: 9999; yourself. buffer := ByteArray new: 256. { buffer. socket waitForDataFor: 60; receiveUDPDataInto: buffer }. "socket closeAndDestroy." And the following terminal code $ echo ABC | nc -u 127.0.0.1 9999 This is on macOS, latest P7. Make sure to not accidentally leave the socket in use. I can't get the broadcast sending via nc to work (like your terminal example). The -b nc option on macOS is not related to broadcasting. But I am sure broadcasting works on my local network. I am playing with Multicast DNS among other things and it works fine, I can receive/resolve .local names in Pharo. I think that is what you should do too, use mDNS. Each Mac supports that (and Linux does too, Raspberry Pi's use it frequently). My mac is called 'prometheus', so it is also known as 'prometheus.local' (like a RPi would be known as 'raspberrypi.local'). The teacher's machine could be called 'teacherpc.local'. In Pharo you then do an mDNS resolve, in the code that I am working on (still experimental), it goes like this: NeoSimplifiedDNSClient new useMulticastDNS; addressForName: 'teacherpc.local'. If all is well, you'll get a SocketAddress back. If the teacher's machine is running a web server, clients can just connect to it using that address. All this provided everybody is on the same local subnet, of course. Doing the networking magic yourself is fun, but might be more work that you expect. BTW, I believe someone did play with UDP broadcasting before, I just can't remember who/when/where. Maybe Henrik ? Sven
On 21 May 2018, at 11:17, Hilaire <hilaire@drgeo.eu> wrote:
Le 21/05/2018 à 10:56, Hilaire a écrit :
Of course I already looked at this Test, but I got lost. I looked at it again, and wrote something like:
Sorry for the badly formated code. By the way the exception handler does not work in the code version bellow. When the ConnectionTimedOut is raised the debugger still show up and the handler is not executed. Strange.
| socket data | socket := Socket newUDP. socket setPort: 9999. socket waitForDataFor: 5 . data := Array new: 100. [[socket receiveUDPDataInto: data. data crLog] on: Error do:[ 'Error, closing socket' crLog. socket closeAndDestroy]] ensure: [ 'Closing socket' crLog. socket closeAndDestroy].
-- Dr. Geo http://drgeo.eu