Dear List,
I am trying to send a UDP broadcast on a Linux host with the following code:
``` s := Socket newUDP.
s setOption: 'SO_BROADCAST' value: 1. [[(Delay forSeconds: numberOfSeconds) wait. s sendUDPData: shoutout toHost: '255.255.255.255' port: (self portNumber) ] repeat] fork. ```
I always get a Primitive Failed error for the sendUDPData message. shoutout is a string in this case.
What am I missing for this example?
Versions used are:
Squeak5.3 latest update: #19470 unix linux-gnu x86_64
Open Smalltalk Cog[Spur] VM [CoInterpreterPrimitives VMMaker.oscog-eem.3142] Unix built on Feb 4 2022 08:41:04 Compiler: Clang 13.0.0 platform sources revision VM: 202201220125
Kind regards,
Christian
Hi Christian
On 4. Feb 2022, at 09:56, Christian Kellermann ckeen@pestilenz.org wrote:
Dear List,
I am trying to send a UDP broadcast on a Linux host with the following code:
s := Socket newUDP. s setOption: 'SO_BROADCAST' value: 1. [[(Delay forSeconds: numberOfSeconds) wait. s sendUDPData: shoutout toHost: '255.255.255.255' port: (self portNumber) ] repeat] fork.
I always get a Primitive Failed error for the sendUDPData message. shoutout is a string in this case.
What am I missing for this example?
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. ```
see also the lone sender of #sendUDPData:toHost:port: and subsequently #sendData:toHost:port: in Socket>>timeTestUDP:
``` "..." serverAddr := NetNameResolver addressForName: serverName timeout: 10. serverAddr = nil ifTrue: [self error: 'Could not find the address for ' , serverName]. s := self newUDP. "a 'random' port number will be allocated by the system" "..." s sendData: '!' toHost: serverAddr port: 13. "13 is the daytime service" Transcript show: 'the time server reports: ' , s receiveData. ```
Best regards -Tobias
Versions used are:
Squeak5.3 latest update: #19470 unix linux-gnu x86_64
Open Smalltalk Cog[Spur] VM [CoInterpreterPrimitives VMMaker.oscog-eem.3142] Unix built on Feb 4 2022 08:41:04 Compiler: Clang 13.0.0 platform sources revision VM: 202201220125
Kind regards,
Christian
Hey Tobias!
* Tobias Pape Das.Linux@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.
Another error state for invalid parameters might have helped here in general though.
Thanks for your patience explaining all this.
Cheers,
Christian
Hey
On 4. Feb 2022, at 17:32, Christian Kellermann ckeen@pestilenz.org wrote:
Hey Tobias!
- Tobias Pape Das.Linux@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/Socke... ) 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/Socke... and, yes, sz was not 4, and yes, primitiveFail should probably be primitiveFailFor(PrimErrBadArgument)
:D
Best regards -Tobias
Cheers,
Christian
beginners@lists.squeakfoundation.org