Hi Hilaire,

Check UDPSocketEchoTest for a good, simple example of using UDP sockets in 
Pharo.

You should not do #connectTo:port: but just #setPort: and listen.

HTH,

Sven

> On 20 May 2018, at 20:59, Hilaire <[email protected]> wrote:
> 
> Hi,
> 
> I try to figure out this matter. I am just new to this domain so excuse me 
> for the obvious the errors.
> 
> To broadcast an IP, this seems to work:
> 
> | socket |
> 
> socket := Socket newUDP.
> socket setOption: 'SO_BROADCAST' value: true.
> 10 timesRepeat: [
>     socket sendUDPData: '10.7.2.1'  toHost: #[255 255 255 255] port: 9999.
>     (Delay forSeconds: 1) wait.
>      ].
> socket closeAndDestroy.
> 
> Then I can listen from the shell: with: nc -ulk 9999
> 
> Now for the listener part, I wrote something like:
> 
> | socket data |
> socket := Socket newUDP.
> socket connectTo: NetNameResolver loopBackAddress port: 9999.
> socket waitForConnectionFor: 2.
> [data := socket receiveDataTimeout: 5.
> data crLog] ensure: [ socket closeAndDestroy]
> 
> But I got an error when connecting the socket, the debugger message is:
> 
> "InvalidSocketStatusException: Socket status must Unconnected before opening 
> a new connection"
> 
> So far I don't see understand this error. Port 9999 is not in use, and 
> running again after this error the broadcast code does not lead to an error.



> Any idea?
> 
> Thanks
> 
> Hilaire
> 
> 
> -- 
> Dr. Geo
> http://drgeo.eu
> 
> 
> 


Reply via email to