Why won't this very simple UDP networking work?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
pauls313
Citizen
Posts: 50
Joined: Tue Aug 02, 2016 3:07 am

Why won't this very simple UDP networking work?

Post by pauls313 »

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
Attachments
Connection.love
(3.49 KiB) Downloaded 147 times
User avatar
pgimeno
Party member
Posts: 3656
Joined: Sun Oct 18, 2015 2:58 pm

Re: Why won't this very simple UDP networking work?

Post by pgimeno »

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:
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.
Edit2: The docs for LuaSocket's setsockname say this:

"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".
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests