Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UDP broadcast example #80

Closed
SolomonViveros opened this issue Jul 26, 2017 · 6 comments
Closed

UDP broadcast example #80

SolomonViveros opened this issue Jul 26, 2017 · 6 comments

Comments

@SolomonViveros
Copy link

Is there any example usage available to demonstrate setting the socket options[if necessary] to allow for a UDP broadcast using the .write(from:,to:) command?

When I write to "192.168.1.255" I get a Udp write Error on a test network that allows broadcasts.

@billabt
Copy link
Collaborator

billabt commented Aug 2, 2017

What error are you getting? Can you show me some code? Thanks.

@SolomonViveros
Copy link
Author

It shows an SOCKET_ERR_WRITE_FAILED - Permission Denied

UdpAsciiBuffer[0] = 48
UdpAsciiBuffer[1] = 49
UdpAsciiBuffer[2] = 50
UdpAsciiBuffer[3] = 51
        
let addr = Socket.createAddress(for: "192.168.1.255", on: UdpPort)
           
do
     {
     try TestUdpSocket?.write(from: UdpAsciiBuffer, to: addr!)
      }
catch let error
    {
    print("Udp write Error")
    }

UdpPort = 1234
If the address is specified to a unique IP, data is sent, but when the IP is set to 255 an error is returned.

@billabt
Copy link
Collaborator

billabt commented Aug 3, 2017

This is fixed in the latest release, 0.12.58. I added a new API, udpBroadcast(enable: Bool), that you should call after creating the socket and before attempting to write to it. See the documentation in the README.md for more info.

@billabt billabt closed this as completed Aug 3, 2017
@SolomonViveros
Copy link
Author

After updating and setting UdpBroadcast to true, a Permission denied error is returned when using the testReadWriteUDP() example function where hostname = "192.168.1.255" and port set to 1234.

Are you able to confirm a "Hello from UDP" udp broadcast across the network using the testReadWriteUDP example function?

@billabt
Copy link
Collaborator

billabt commented Aug 3, 2017

Sorry, I had a typo in udpBroadcast. It's fixed in the 0.12.59 release. It was actually disabling the broadcast instead of enabling it.

@SolomonViveros
Copy link
Author

Awesome! Works now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants