Python UDP Broadcast

Asked

Viewed 129 times

0

In python 3.7, when I send a broadcast (via UDP), you need to specify the port. Is there any way I don’t need to do this? Example:

socket.sendto(b, ('<broadcast>', 15000)); #Nesse eu especifico a porta

socket.sendto(b, ('<broadcast>')); #Nesse o programa identifica automaticamente a porta do cliente

data, ip = s1.recvfrom(2048)
ip[1] #É a porta que o servidor deveria enviar o broadcast para o cliente, mas isso iria variar para cada cliente.

I wanted to do it the second way, but he makes that mistake:

TypeError: getsockaddrarg: AF_INET address must be tuple, not str
  • Without specifying the port, to which of them the message should be sent?

  • I edited on the topic.

1 answer

0

Regardless of whether it is Python or another language, when broadcasting, you need to specify a port. Actually the question does not even make sense, when using UDP (or TCP) to exchange messages it is always necessary to specify a port.

  • I don’t think you understand. The port would be specified, but not by me. It would be specified by the <broadcast parameter>.

  • Basically: Suppose <broadcast> is a list of IP’s that have connected/are connected to the socket. This means that he knows the IP that should send the information. There would be a way for him to know the port the client used as well?

  • Yeah, I really don’t get it...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.