BlueSocket
BlueSocket copied to clipboard
Unable to bind to source address UDP
I can't find the way to bind to a specific interface/IP using the UDP socket. I tried with something similar to:
try socket.listen(on: self.port, maxBacklogSize: Socket.SOCKET_DEFAULT_MAX_BACKLOG, allowPortReuse: false, node: "my IP address")
let (bytes, address) = try socket.readDatagram(into: &data)
But that way I don't receive any data. What am I doing wrong?
What are you passing in the node parameter? The value must be a String containing the numeric representation of the address you’re trying to connect to.
I'm passing the ip of the wifi card as a string (in my case "10.1.0.16"). Is that right? It seems like it binds properly (if I pass gibberish I get a unable to bind error) but after that I don't receive anything when I try to send. Wireshark sees the packet coming in though.
Can you give me an example? I’ve tried it here and it seems to be working fine.
This is what I use at the moment: the data arrives to the interface but the code never goes past the socket.listen
line.
If I don't specify the node and use directly: func listen(forMessage data: inout Data, on port: Int, maxBacklogSize: Int
then it all works, but only locally if I send messages to 127.0.0.1.
let listenSocket = try Socket.create(family: .inet, type: .datagram, proto: .udp)
var data = Data()
try socket.listen(on: self.port, maxBacklogSize: Socket.SOCKET_DEFAULT_MAX_BACKLOG, allowPortReuse: false, node: "10.1.0.16")
let (bytes, address) = try socket.readDatagram(into: &data)
print("Read \(bytes) from \(String(describing: address))")
I’ll look into it a bit deeper. Hopefully I can reproduce it.
Thanks, let me know if I can assist grabbing some extra debug data for you.
After a bit of digging it looks like I get nothing on macOS (Mojave) but I get Error code: -9996(0x-270C), The socket is not connected
on Linux (ubuntu 18.04) when trying to reply back with a message on the same socket