[Twisted-Python] udp
How do you send data using udp? I want to use udp to send messages from clients to a server. I don't want to use connected udp. Can anyone supply some specimen code for me Thanks Bruce Coram
If you are not receiving datagrams on the client side, is there any reason to use twisted for the client side? You could just pump datagrams out when you need to send something. Bruce Coram wrote:
How do you send data using udp?
I want to use udp to send messages from clients to a server. I don't want to use connected udp.
Can anyone supply some specimen code for me
Thanks
Bruce Coram
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Like Carl suggested, I just eschewed Twisted on the client side when I did something similar. Here is a simple client that can be used with the server I sent earlier. import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) data = "Data from client" s.sendto(data, ('localhost', 8000)) data,address = s.recvfrom(1024) print "received %r from %r" % (data, address) If you don't want the server to send anything back, you can skip the recvfrom() on the client side and the self.transport.write() on the server side. Of course, this doesn't include any error handling for when the UDP data doesn't actually make it (which, of course, isn't guaranteed) - but this is just to illustrate how simple it is. -Black On Jun 14, 2007, at 3:54 PM, Carl Zmola wrote:
If you are not receiving datagrams on the client side, is there any reason to use twisted for the client side? You could just pump datagrams out when you need to send something.
Bruce Coram wrote:
How do you send data using udp?
I want to use udp to send messages from clients to a server. I don't want to use connected udp.
Can anyone supply some specimen code for me
Thanks
Bruce Coram
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Many thanks for the help. I had hoped to be able to use Twisted's udp but it makes no real difference. Thanks Bruce
Like Carl suggested, I just eschewed Twisted on the client side when I did something similar. Here is a simple client that can be used with the server I sent earlier.
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) data = "Data from client" s.sendto(data, ('localhost', 8000)) data,address = s.recvfrom(1024) print "received %r from %r" % (data, address)
If you don't want the server to send anything back, you can skip the recvfrom() on the client side and the self.transport.write() on the server side. Of course, this doesn't include any error handling for when the UDP data doesn't actually make it (which, of course, isn't guaranteed) - but this is just to illustrate how simple it is.
-Black
On Jun 14, 2007, at 3:54 PM, Carl Zmola wrote:
If you are not receiving datagrams on the client side, is there any reason to use twisted for the client side? You could just pump datagrams out when you need to send something.
Bruce Coram wrote:
How do you send data using udp?
I want to use udp to send messages from clients to a server. I don't want to use connected udp.
Can anyone supply some specimen code for me
Thanks
Bruce Coram
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
On Thu, 14 Jun 2007 20:42:47 +0100, Bruce Coram <brucecoram@clara.co.uk> wrote:
How do you send data using udp?
I want to use udp to send messages from clients to a server. I don't want to use connected udp.
Can anyone supply some specimen code for me
Consider using TCP instead: http://twistedmatrix.com/projects/core/documentation/howto/servers.html http://twistedmatrix.com/projects/core/documentation/howto/clients.html It's probably much better suited to your application than UDP. However, there is UDP documentation on the website as well: http://twistedmatrix.com/projects/core/documentation/howto/udp.html Jean-Paul
participants (4)
-
Black -
Bruce Coram -
Carl Zmola -
Jean-Paul Calderone