This commit is contained in:
2015-06-02 21:38:24 +02:00
parent 219ffcce0f
commit 1151d6893e
5 changed files with 141 additions and 0 deletions

16
socketserver/UdpClient.py Normal file
View File

@@ -0,0 +1,16 @@
import socket
import sys
HOST, PORT = "localhost", 9999
data = " ".join(sys.argv[1:])
# SOCK_DGRAM is the socket type to use for UDP sockets
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# As you can see, there is no connect() call; UDP has no connections.
# Instead, data is directly sent to the recipient via sendto().
sock.sendto(data + "\n", (HOST, PORT))
received = sock.recv(1024)
print "Sent: {}".format(data)
print "Received: {}".format(received)