By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,046 Members | 2,105 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,046 IT Pros & Developers. It's quick & easy.

SocketServer broadcast

P: n/a
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 !!
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Dec 19, 2003, at 10:51 AM, Olivier Hoarau wrote:
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.


Are you saying you have working server client/server code that works,
but doesn't use the SocketServer ?
If so, could you post it ?

I've been trying to do the same thing, though I'd be fine with it not
using the Socketserver, but no success. Sorry.
Torsten
Jul 18 '05 #2

P: n/a


Torsten Rueger a écrit :
If so, could you post it ?


Of course

The server

import socket
import sys
import time

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

print "Port diffusion en fonction",PORT

service = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
service.setsockopt( socket.SOL_SOCKET, socket.SO_BROADCAST, 1 )
service.connect((GROUP,PORT))

while 1:
contenu=time.ctime(time.time())
service.send(contenu)
print "Message envoye"
time.sleep(1)

service.close()

And the client

import socket
import sys

host='192.168.20.73'
port=10000

s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((host, port))

while 1:
t,server=s.recvfrom(65535)
print t

s.close()

I hope it will help
Olivier
Jul 18 '05 #3

P: n/a
On Dec 19, 2003, at 12:44 PM, Olivier Hoarau wrote:

Of course


Thanks a bunch!

I don't have client or servers really, just peers. So I need to have
both client + server in the same process.

When I do that, the client bind fails. But when I bind to '' (empty
string) then it works. Maybe that helps you too (?)

Anyway, it works for me now, thanks a lot

Torsten
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.