How do you issue a network broadcast in sockets?

0 Jesse Cox · January 29, 2015
I have the following (modified) code from the Python docs:

import socket

def send(ip, message):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((ip, 4601))
    try:
        sock.sendall(message)
        response = sock.recv(1024)
    finally:
        sock.close()
    if response:
        return response
    else:
        return False


When substituting ip with "<broadcast>" I get "OSError: [Errno 101] Network is unreachable"

Post a Reply

Replies

Oldest  Newest  Rating
0 Jesse Cox · January 31, 2015
Sorry I didn't fix the question here. The problem was that broadcasts only work on UDP. Thanks for your answer as well.
0 Samuel Oloruntoba · January 30, 2015
is this helpful http://stackoverflow.com/questions/18080094/how-to-make-a-server-discoverable-to-lan-clients
  • 1

Python

107,092 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator