[Vm-dev] [Newbies] Sending UDP broadcasts

Tobias Pape Das.Linux at gmx.de
Fri Feb 4 16:54:36 UTC 2022


Hey

> On 4. Feb 2022, at 17:32, Christian Kellermann <ckeen at pestilenz.org> wrote:
> 
> Hey Tobias!
> 
> * Tobias Pape <Das.Linux at gmx.de> [220204 14:46]:
>> The host is not a string but rather an address. Try this:
>> 
>> ```
>> addr :=  NetNameResolver addressForName: '255.255.255.255' timeout: 10.
>> s := Socket newUDP.
>> 
>> s setOption:  'SO_BROADCAST' value: 1.
>> [[(Delay forSeconds: numberOfSeconds) wait.
>> 	 s sendUDPData: shoutout toHost: addr port: (self portNumber) ]
>> repeat] fork.
>> ```
> 
> Oh, duh! Yes of course. I stopped at the <prim> call pragma, I should have gone deeper.
> I somehow missed the example in the code.

No worries!


> 
> Another error state for invalid parameters might have helped here in general though.

Funnily enough, the primitive does this for all sort of things:
(c code generated from SLANG:
	https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/src/plugins/SocketPlugin/SocketPlugin.c#L2053
) but not the host.
This might be because things changed over time, and, indeed, there used to be a variant to pass
a host in a different manner.

> 
> Thanks for your patience explaining all this.

No, no worries at all.
I actually debugged the VM until i reached here:
	https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/src/plugins/SocketPlugin/SocketPlugin.c#L2108
and, yes, sz was not 4, and yes, primitiveFail should probably be primitiveFailFor(PrimErrBadArgument) 

:D

Best regards
	-Tobias
> 
> Cheers,
> 
> Christian





More information about the Vm-dev mailing list