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.2 0.73'
PORT=10000
class BroadcastAcquis ition(SocketSer ver.UDPServer,
SocketServer.Th readingMixIn):
def __init__(self, address, handler):
self.allow_reus e_address = 1
SocketServer.UD PServer.__init_ _(self, address, handler)
class Handler(SocketS erver.DatagramR equestHandler):
def handle(self):
print self.packet
s = BroadcastAcquis ition(('', 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.2 0.73'
PORT=10000
class Broadcast(Socke tServer.UDPServ er, SocketServer.Th readingMixIn):
def __init__(self, address, handler):
self.allow_reus e_address = 1
SocketServer.UD PServer.__init_ _(self, address, handler)
class Handler(SocketS erver.DatagramR equestHandler):
def handle(self):
contenu=time.ct ime(time.time() )
self.send(conte nu)
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 4170
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.2 0.73'
PORT=10000
print "Port diffusion en fonction",PORT
service = socket.socket( socket.AF_INET, socket.SOCK_DGR AM )
service.setsock opt( socket.SOL_SOCK ET, socket.SO_BROAD CAST, 1 )
service.connect ((GROUP,PORT))
while 1:
contenu=time.ct ime(time.time() )
service.send(co ntenu)
print "Message envoye"
time.sleep(1)
service.close()
And the client
import socket
import sys
host='192.168.2 0.73'
port=10000
s=socket.socket (socket.AF_INET , socket.SOCK_DGR AM)
s.setsockopt(so cket.SOL_SOCKET , socket.SO_REUSE ADDR, 1)
s.bind((host, port))
while 1:
t,server=s.recv from(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 functionalty
but connecting to a server.
I have no idea about programming with python so every hint is a present
for me :)
------------------------------------
import SocketServer
import os
|
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 GreetingHandler(SocketServer.BaseRequestHandler):
'''Class to handle sending a greeting to a client
'''
|
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 of code in the
program result in the errors given below:
import SocketServer
print "SocketServer imported"
|
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 handle_request loop
instead of serve_forever, it still seems difficult:
class myserver(ThreadingMixIn, TCPServer): pass
server = myserver(...)
server.shutdown = False
while not server.shutdown:
server.handle_request()
|
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 again, but if I let it run out of data,
and exit via handle_error as can be seen below, I will get
a socket.error: (98, 'Address already in use') when I try
to restart the server. (Unless I wait a minute or so, or
use another port.) I feel like I'm...
| |
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 socket.setdefaulttimeout()
work? Does it timeout the initial connect request to the socket server
or does it timeout the session between the connecting client socket and
the client socket the server generated to handle the incoming request?
Also, since the...
|
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?
import SocketServer
import logging as l
l.basicConfig(level=l.DEBUG,
|
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 and
answers requests.
All went fine until I realized that I have to sometimes stop the
server - which is where I ran into a problem. Python threads can not
be killed after they've been started. They can be kindly requested to
|
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 serve_forever, shutdown will
never return.
This can happen when a server is stopped during startup.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |