473,246 Members | 1,260 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

SocketServer broadcast

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
3 4128
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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ergin Aytac | last post by:
I'm trying to run a script written in python and have some socket connection problems. I cutted the origin script (more than 1000 lines) so it is only the part of the connection and there is no...
0
by: Adil Hasan | last post by:
Hello Fred, I just ran across your question. I think that the following code will work: ----- SERVER CODE ------ import SocketServer import time class...
5
by: missiplicity | last post by:
Hi, I am newbie to Python language and am taking my baby steps. I am using Python2.4 from ActiveState on W2K. I am trying to create a simple SocketServer program. Just adding the following 2 lines...
12
by: Paul Rubin | last post by:
Let's say you have a SocketServer with the threading mix-in and you run serve_forever on it. How can you shut it down, or rather, how can it even shut itself down? Even if you use a...
3
by: Magnus Lycka | last post by:
I have a socket server like below which I want to exit when it's out of data. If I interrupt the client, I'll get a broken pipe on the server side, and after a Ctrl-C, I can restart the server...
1
by: rbt | last post by:
I've read more about sockets and now, I have a better understanding of them. However, I still have a few SocketServer module questions: When used with SocketServer how exactly does...
0
by: Tomi Hautakoski | last post by:
Hello, I'm a Python newbie trying to figure out how to use SocketServer with IPv6. I would like to set up a TCPServer working like below but how to tell SocketServer I need to use AF_INET6? ...
5
by: eliben | last post by:
Hello, I have a small wxPython application. Today I was trying to add some RPC capability to it, so I implemented an instance of SimpleXMLRPCServer that runs in a separate thread when invoked...
1
by: Okko Willeboordse | last post by:
All, With Python 2.5 SocketServer features the shutdown method that can be called from another thread to stop the serve_forever loop. However; When the shutdown method is called before...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.