SocketServer broadcast

Olivier Hoarau olivier.hoarau at mortauxspams.bz
Fri Dec 19 09:51:28 CET 2003


Hello,

I have build a client/server application with the socket module. The
server mades UDP broadcasting and the client only reads UDP broadcast
messages. All work fine.
Now I want to use for the same thing the socketserver module, it's ok
for the client, but I don't succeed in making work the server :-((

Here is the client (which works)

import sys
import SocketServer

host='192.168.20.73'
PORT=10000

class BroadcastAcquisition(SocketServer.UDPServer,
SocketServer.ThreadingMixIn):
    def __init__(self, address, handler):
        self.allow_reuse_address = 1
        SocketServer.UDPServer.__init__(self, address, handler)

class Handler(SocketServer.DatagramRequestHandler):
  def handle(self):
    print self.packet
                                
s = BroadcastAcquisition(('', PORT), Handler)
s.serve_forever()


And the server (doesn't work)

import sys
import time
import SocketServer

GROUP = '192.168.20.255'
HOST='192.168.20.73'
PORT=10000

class Broadcast(SocketServer.UDPServer, SocketServer.ThreadingMixIn):
    def __init__(self, address, handler):
        self.allow_reuse_address = 1
        SocketServer.UDPServer.__init__(self, address, handler)

class Handler(SocketServer.DatagramRequestHandler):
        def handle(self):
                contenu=time.ctime(time.time())
                self.send(contenu)
                print "Message envoye"
                time.sleep(1)


s = Broadcast(('', PORT), Handler)
s.serve_forever()

I know I have to set the SO_BROADCAST attribute and the network mask for
the broadcast but I don't know how and where in the programm.

Olivier
PS: Excuse for my poor english !!




More information about the Python-list mailing list