summaryrefslogtreecommitdiff
path: root/tests/circuitpython-manual/socketpool/client/cpy-client.py
blob: dcc742c9f8f329a4ce8923bbe1c90df4742a6bb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import wifi
import socketpool
import ssl
import time

TIMEOUT = None
HOST = '192.168.10.179'
PORT = 5000

# Connect to wifi
print("Connecting to wifi")
wifi.radio.connect("mySSID", "myPASS")
pool = socketpool.SocketPool(wifi.radio)

print("Creating Socket")
with pool.socket(pool.AF_INET, pool.SOCK_STREAM) as s:
    s.settimeout(TIMEOUT)

    print("Connecting")
    s.connect((HOST, PORT))
    print("Sending")
    sent = s.send(b'Hello, world')
    print("Receiving")
    buff = bytearray(128)
    numbytes = s.recv_into(buff)
print(repr(buff))