This is a very very simple attempt at networking with unconnected UDP objects, but I don't understand why it won't work.
Client = sends information
Server = receives information
Press t to change type
Why won't this very simple UDP networking work?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Why won't this very simple UDP networking work?
- Attachments
-
- Connection.love
- (3.49 KiB) Downloaded 151 times
Re: Why won't this very simple UDP networking work?
The semantics of not using setsockname() on the server are not clear to me, as there's no port defined. The LuaSocket manual says:
"To associate an UDP socket with a local address, an application calls the setsockname method before sending any datagrams. Otherwise, the socket is automatically bound to an ephemeral address before the first data transmission and once bound the local address cannot be changed".
However, I could not make it work until I used setsockname first.
Edit: If it works according to the udp(7) manpage, it seems it's listening on some automatically assigned port:
"Note: This method can only be called before any datagram is sent through the UDP object, and only once. Otherwise, the system automatically binds the object to all local interfaces and chooses an ephemeral port as soon as the first datagram is sent. After the local address is set, either automatically by the system or explicitly by setsockname, it cannot be changed".
"To associate an UDP socket with a local address, an application calls the setsockname method before sending any datagrams. Otherwise, the socket is automatically bound to an ephemeral address before the first data transmission and once bound the local address cannot be changed".
However, I could not make it work until I used setsockname first.
Edit: If it works according to the udp(7) manpage, it seems it's listening on some automatically assigned port:
Edit2: The docs for LuaSocket's setsockname say this:udp(7) manpage wrote: In
order to receive packets, the socket can be bound to a local address
first by using bind(2). Otherwise, the socket layer will automatically
assign a free local port out of the range defined by
/proc/sys/net/ipv4/ip_local_port_range and bind the socket to
INADDR_ANY.
"Note: This method can only be called before any datagram is sent through the UDP object, and only once. Otherwise, the system automatically binds the object to all local interfaces and chooses an ephemeral port as soon as the first datagram is sent. After the local address is set, either automatically by the system or explicitly by setsockname, it cannot be changed".
Who is online
Users browsing this forum: Bing [Bot], GoldenTCat, Google [Bot] and 4 guests