MCPcopy Create free account
hub / github.com/Apress/python-for-matlab-development / main

Function main

code/IO/tcp/client.py:49–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

47 return Bytes
48
49def main():
50 Host, Port = '127.0.0.1', 5006
51 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
52 s.connect((Host, Port))
53 for i in range(10):
54 N = np.random.randint(3,10) # 3 <= N < 10
55 A = np.random.rand(N,N)
56 s.send(struct.pack('q',N)) # send N
57 print(f'sending A ({N:2d} x {N:2d}) ',end='')
58 s.send(A.tobytes()) # send A
59 Bytes = wait_for_nBytes(8*N*N, s)
60 Ainv = np.frombuffer(Bytes, dtype=np.float64)
61 # could also do
62 # Ainv = np.array(struct.unpack(f'{N*N}d',Bytes))
63 Ainv = Ainv.reshape(N,N)
64 err = np.max(np.eye(N) - A@Ainv)
65 print(f'err = {err:e}')
66 s.close()
67if __name__ == "__main__": main()

Callers 1

client.pyFile · 0.70

Calls 1

wait_for_nBytesFunction · 0.85

Tested by

no test coverage detected