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 !! 3 4140
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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?
...
|
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...
|
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...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |