On 23-8-2013 14:32, [email protected] wrote:
> I want to send a broadcast packet to all the computers connected to my home
> router.
>
> The following 2 lines of code do not work;
> host="192.168.0.102"
> s.connect((host, port))
>
> Can someone advise?
>
> Thank you.
>
Use UDP (datagram) sockets. Use sendto() and not connect(), because UDP is
connectionless. This should work:
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(b"thedata", 0, ("<broadcast>", 9999)) # 9999 = port
sock.close()
Irmen
--
http://mail.python.org/mailman/listinfo/python-list