Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/python/python-wasm/data/socket/client.py
1067 views
1
"""
2
3
Run the server first, then run this via
4
5
python-wasm client.py
6
7
You can also run either the client or server with python-native
8
to narrow down problems.
9
10
"""
11
12
import socket, time
13
14
15
def f():
16
# TODO: This currently "hangs for 5 seconds" even
17
# though the other side is ready. The problem
18
# is that poll_oneoff or pollSocket (in posix-node)
19
# need to be improved.
20
conn = socket.create_connection(("localhost", 2000), timeout=5)
21
print("connected to port 2000")
22
#conn.settimeout(1)
23
24
print("*" * 80)
25
print("conn =", conn)
26
print("*" * 80)
27
28
t = time.time()
29
print(conn.recv(6))
30
print("time = ", time.time() - t)
31
32
t = time.time()
33
print(conn.send(b"CoWasm"))
34
print("time = ", time.time() - t)
35
36
#conn.shutdown(socket.SHUT_RD)
37
38
39
f()
40
41