summaryrefslogtreecommitdiffstats
path: root/Demo/sockets/udpecho.py
diff options
context:
space:
mode:
Diffstat (limited to 'Demo/sockets/udpecho.py')
-rwxr-xr-xDemo/sockets/udpecho.py82
1 files changed, 41 insertions, 41 deletions
diff --git a/Demo/sockets/udpecho.py b/Demo/sockets/udpecho.py
index 720cfe1..5181c82 100755
--- a/Demo/sockets/udpecho.py
+++ b/Demo/sockets/udpecho.py
@@ -12,52 +12,52 @@ ECHO_PORT = 50000 + 7
BUFSIZE = 1024
def main():
- if len(sys.argv) < 2:
- usage()
- if sys.argv[1] == '-s':
- server()
- elif sys.argv[1] == '-c':
- client()
- else:
- usage()
+ if len(sys.argv) < 2:
+ usage()
+ if sys.argv[1] == '-s':
+ server()
+ elif sys.argv[1] == '-c':
+ client()
+ else:
+ usage()
def usage():
- sys.stdout = sys.stderr
- print 'Usage: udpecho -s [port] (server)'
- print 'or: udpecho -c host [port] <file (client)'
- sys.exit(2)
+ sys.stdout = sys.stderr
+ print 'Usage: udpecho -s [port] (server)'
+ print 'or: udpecho -c host [port] <file (client)'
+ sys.exit(2)
def server():
- if len(sys.argv) > 2:
- port = eval(sys.argv[2])
- else:
- port = ECHO_PORT
- s = socket(AF_INET, SOCK_DGRAM)
- s.bind(('', port))
- print 'udp echo server ready'
- while 1:
- data, addr = s.recvfrom(BUFSIZE)
- print 'server received %r from %r' % (data, addr)
- s.sendto(data, addr)
+ if len(sys.argv) > 2:
+ port = eval(sys.argv[2])
+ else:
+ port = ECHO_PORT
+ s = socket(AF_INET, SOCK_DGRAM)
+ s.bind(('', port))
+ print 'udp echo server ready'
+ while 1:
+ data, addr = s.recvfrom(BUFSIZE)
+ print 'server received %r from %r' % (data, addr)
+ s.sendto(data, addr)
def client():
- if len(sys.argv) < 3:
- usage()
- host = sys.argv[2]
- if len(sys.argv) > 3:
- port = eval(sys.argv[3])
- else:
- port = ECHO_PORT
- addr = host, port
- s = socket(AF_INET, SOCK_DGRAM)
- s.bind(('', 0))
- print 'udp echo client ready, reading stdin'
- while 1:
- line = sys.stdin.readline()
- if not line:
- break
- s.sendto(line, addr)
- data, fromaddr = s.recvfrom(BUFSIZE)
- print 'client received %r from %r' % (data, fromaddr)
+ if len(sys.argv) < 3:
+ usage()
+ host = sys.argv[2]
+ if len(sys.argv) > 3:
+ port = eval(sys.argv[3])
+ else:
+ port = ECHO_PORT
+ addr = host, port
+ s = socket(AF_INET, SOCK_DGRAM)
+ s.bind(('', 0))
+ print 'udp echo client ready, reading stdin'
+ while 1:
+ line = sys.stdin.readline()
+ if not line:
+ break
+ s.sendto(line, addr)
+ data, fromaddr = s.recvfrom(BUFSIZE)
+ print 'client received %r from %r' % (data, fromaddr)
main()