Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > UDP Client/Server

Reply
Thread Tools

UDP Client/Server

 
 
Martin Marcher
Guest
Posts: n/a
 
      01-22-2008
Hello,

I created a really simple udp server and protocol but I only get every 2nd
request (and thus answer just every second request).

Maybe someone could shed some light, I'm lost in the dark(tm), sorry if this
is a bit oververbose but to me everything that happens here is black magic,
and I have no clue where the packages go. I can't think of a simpler
protocol than to just receive a fixed max UDP packet size and answer
immediately (read an "echo" server).

thanks
martin


### server
>>> from socket import *
>>> import SocketServer
>>> from SocketServer import BaseRequestHandler, UDPServer
>>> class FooReceiveServer(SocketServer.UDPServer):

.... def __init__(self):
.... SocketServer.UDPServer.__init__(self, ("localhost", 4321),
FooRequestHandler)
....
>>> class FooRequestHandler(BaseRequestHandler):

.... def handle(self):
.... data, addr_info = self.request[1].recvfrom(65534)
.... print data
.... print addr_info
.... self.request[1].sendto("response", addr_info)
....
>>> f = FooReceiveServer()
>>> f.serve_forever()

request 0
('127.0.0.1', 32884)
request 1
('127.0.0.1', 32884)
request 2
('127.0.0.1', 32884)
request 2
('127.0.0.1', 32884)
request 2
('127.0.0.1', 32884)



### client
>>> target = ('127.0.0.1', 4321)
>>> from socket import *
>>> s = socket(AF_INET, SOCK_DGRAM)
>>> for i in range(10):

.... s.sendto("request " + str(i), target)
.... s.recv(65534)
....
9
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
KeyboardInterrupt
>>> s.sendto("request " + str(i), target)

9
>>> str(i)

'0'
>>> for i in range(10):

.... s.sendto("request " + str(i), target)
.... s.recv(65534)
....
9
'response'
9
'response'
9
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
KeyboardInterrupt
>>> #this was hanging, why?

....
>>> s.sendto("request " + str(i), target)

9
>>> s.recv(65534)

'response'
>>> s.sendto("request " + str(i), target)

9
>>> s.recv(65534)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyboardInterrupt
>>> s.sendto("request " + str(i), target)

9
>>> s.sendto("request " + str(i), target)

9
>>> s.recv(65534)

'response'
>>> s.recv(65534)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyboardInterrupt
>>> s.sendto("request " + str(i), target)

9
>>>


--
http://noneisyours.marcher.name
http://feeds.feedburner.com/NoneIsYours

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
udp (0) -> udp (0) traffic ? Tom Cisco 2 03-04-2004 06:06 PM
Re: tired of counting.... UDP socket bug Willy Denoyette [MVP] ASP .Net 0 01-13-2004 08:57 PM
Re: tired of counting.... UDP socket bug Ray Cassick \(Home\) ASP .Net 3 01-13-2004 06:53 PM
Re: 4th attempt: UDP Socket Bug Chris Botha ASP .Net 3 01-09-2004 12:47 AM
3rd attempt: UDP Socket Bug Bryan Martin ASP .Net 1 01-07-2004 09:06 PM



Advertisments