move towards single implementation for socket client/server using asyncore and threads

This commit is contained in:
2015-09-06 22:48:23 +01:00
parent 97613337c6
commit ba882d7e2b
18 changed files with 158 additions and 243 deletions

23
datagram/UdpSender.py Normal file
View File

@@ -0,0 +1,23 @@
import socket
import sys
# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = ('localhost', 10000)
message = 'This is the message. It will be repeated.'
try:
# Send data
print >>sys.stderr, 'sending "%s"' % message
sent = sock.sendto(message, server_address)
# Receive response
print >>sys.stderr, 'waiting to receive'
data, server = sock.recvfrom(4096)
print >>sys.stderr, 'received "%s"' % data
finally:
print >>sys.stderr, 'closing socket'
sock.close()