udp, datagram sockets
7stud
bbxx789_05ss at yahoo.com
Mon Aug 6 18:46:55 EDT 2007
On Aug 6, 1:27 pm, Carsten Haese <cars... at uniqsys.com> wrote:
> I don't think that sending the datagram to port 7777 on localhost sends
> the message back to the client. I'm guessing the server is sending the
> message back to itself, which throws it into the infinite feedback loop
> you're experiencing.
>
Thanks.
On Aug 6, 2:14 pm, anethema <jefish... at gmail.com> wrote:
> Yes, you want to use the socket.recvfrom() method, store the address,
> and send the response to that address. Your code is indeed repeatedly
> sending itself the received message.
>
> You want to change
>
>> data = s.recv(1024)
>
> to
>
> data, recv_addr = s.recvfrom(1024)
>
> and
>
>> size_sent = s.sendto(message[total_sent:], ("localhost",
>> 7777) )
>
> to
>
> size_sent = s.sendto(message[total_sent:], recv_addr)
>
Thanks for the details.
> However, your client closes immediately after sending all its data, so
> it will never receive that message.
>
Yes, I commented out the recv() part of the client to debug the
infinite loop I was experiencing. When I add that back to the client
everything works as it should.
Thanks to both of you again.
More information about the Python-list
mailing list