add example using serversocket from https://docs.python.org/2/library/socketserver.html
This commit is contained in:
16
socketserver/UdpClient.py
Normal file
16
socketserver/UdpClient.py
Normal 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)
|
||||
Reference in New Issue
Block a user