summaryrefslogtreecommitdiff
path: root/tests/circuitpython-manual/socketpool/server/cpy-server.py
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2021-02-25 16:59:15 -0800
committerScott Shawcroft <scott@tannewt.org>2021-02-25 16:59:15 -0800
commit3f08cb47b846fff41ef9a45d49758f0cef61e723 (patch)
tree66d5093b24d127a1fb60cc70f5087b39e87fbff5 /tests/circuitpython-manual/socketpool/server/cpy-server.py
parent52bc935fa7aa9e5c94f75fec8b2fa746c83f0be7 (diff)
parentb69cb0144ca0d54011be540213d1e25e673a63de (diff)
Merge remote-tracking branch 'adafruit/main' into busio-uart-rp
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]])