Tests for the NetworkSocketAPI
Dependents: BSDInterfaceTests ESP8266InterfaceTests LWIPInterfaceTests SpwfInterface_NSAPI_Tests ... more
Revision 12:152ae238ddc1, committed 2016-06-06
- Comitter:
- mridup
- Date:
- Mon Jun 06 08:42:21 2016 +0000
- Parent:
- 11:fbfe3498404a
- Commit message:
- -set socket options before ?socket.bind?; -listen for incoming SOCK_STREAM connections only before ?socket.accept?; ; resolves error in ubuntu linux ("address already in use"); ;
Changed in this revision
EchoServer.py | Show annotated file Show diff for this revision Revisions of this file |
diff -r fbfe3498404a -r 152ae238ddc1 EchoServer.py --- a/EchoServer.py Tue May 10 21:38:38 2016 -0500 +++ b/EchoServer.py Mon Jun 06 08:42:21 2016 +0000 @@ -8,26 +8,24 @@ port = int(port) udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) udp.bind(('', port)) - udp.setblocking(0) - udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + udp.setblocking(0) tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) tcp.bind(('', port)) tcp.setblocking(0) - tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - tcp.listen(5) udp6 = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) + udp6.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) udp6.bind(('', port)) - udp6.setblocking(0) - udp6.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + udp6.setblocking(0) tcp6 = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) + tcp6.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) tcp6.bind(('', port)) tcp6.setblocking(0) - tcp6.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - tcp6.listen(5) print "running on port %d" % port sockets = [tcp, udp, tcp6, udp6] @@ -44,6 +42,7 @@ pass try: + tcp.listen(5) client, addr = tcp.accept() print 'tcp %s:%d connect' % (addr[0], addr[1]) client.setblocking(0) @@ -61,6 +60,7 @@ pass try: + tcp6.listen(5) client, addr = tcp6.accept() print 'tcp6 %s:%d connect' % (addr[0], addr[1]) client.setblocking(0)