summaryrefslogtreecommitdiff
path: root/tests/circuitpython-manual/socketpool/server/cpy-server.py
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2021-02-19 18:44:27 -0800
committerGitHub <noreply@github.com>2021-02-19 18:44:27 -0800
commit5d154937d68a29d90d86e45467c4ebc134252855 (patch)
tree535bbb96c393b6e722a70febd87c2ad931656aeb /tests/circuitpython-manual/socketpool/server/cpy-server.py
parentfdf9d04a75d71f16b5e715ab3240e900ca66f1f8 (diff)
parente77981f86e53eb5a985e89e03cc984e5b318da37 (diff)
Merge pull request #4187 from hierophect/manual-tests
Create tests/_manual, add Socket tests
Diffstat (limited to 'tests/circuitpython-manual/socketpool/server/cpy-server.py')
-rw-r--r--tests/circuitpython-manual/socketpool/server/cpy-server.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/circuitpython-manual/socketpool/server/cpy-server.py b/tests/circuitpython-manual/socketpool/server/cpy-server.py
new file mode 100644
index 000000000..d865156bc
--- /dev/null
+++ b/tests/circuitpython-manual/socketpool/server/cpy-server.py
@@ -0,0 +1,31 @@
+import wifi
+import socketpool
+
+TIMEOUT = None
+
+print("Connecting to Wifi")
+wifi.radio.connect("mySSID", "myPASS")
+
+pool = socketpool.SocketPool(wifi.radio)
+
+print("Finding IP address")
+print(wifi.radio.ipv4_address)
+HOST = str(wifi.radio.ipv4_address)
+PORT = 80 # Port to listen on
+
+print("Creating socket")
+sock = pool.socket(pool.AF_INET,pool.SOCK_STREAM)
+
+sock.bind((HOST, PORT))
+sock.listen(1)
+print("Accepting connections")
+conn, addr = sock.accept()
+with conn:
+ print('Connected by', addr)
+ buff = bytearray(128)
+ print("Receiving")
+ numbytes = conn.recvfrom_into(buff)
+ print(buff[:numbytes[0]])
+ if numbytes:
+ print("Sending")
+ conn.send(buff[:numbytes[0]])