UDP client-server problem

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Tue Jul 15 18:25:07 EDT 2003


WIWA wrote:

> The question is: when I add  "svrsocket.sendto(resultaat, (ip, port))"
> in the UDP server, my application closes while running. When I leave
> it away, it works fine. I really need this statement as the purpose is
> that a client sends sth to the server and the server sends back the
> time ticks.

It would have helped if you were more specific about: "closes while running"?
In my case (running your code) I get an exception in the server:


Traceback (most recent call last):
   File "server.py", line 44, in ?
     svrsocket.sendto(resultaat, (ip, port))
   File "<string>", line 1, in sendto
TypeError: sendto() takes exactly 3 arguments (2 given)


this pretty much tells you what's wrong. Your sendto() call is faulty.

The first argument in your case is of type <float> while it should be
a <string>. So try

     svrsocket.sendto(str(resultaat), (ip, port))

however, this triggers a loop in your code if your client is on the
same machine as the server (the server sends out a UDP packet to the
same port as it itself is listening on, on my machine, it gets back
its own UDP packet....)

HTH,
--Irmen de Jong







More information about the Python-list mailing list