()
| 34 | from client import wait_for_nBytes |
| 35 | |
| 36 | def main(): |
| 37 | Host, Port = 'localhost', 5006 |
| 38 | |
| 39 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 40 | s.bind((Host, Port)) |
| 41 | s.listen(1) |
| 42 | |
| 43 | conn, addr = s.accept() |
| 44 | while True: |
| 45 | try: |
| 46 | Bytes = wait_for_nBytes(8, conn) # get bytes of N |
| 47 | if not Bytes: |
| 48 | break |
| 49 | N = struct.unpack(f'q', Bytes)[0] # bytes -> N |
| 50 | print(f'got N={N}') |
| 51 | Bytes = wait_for_nBytes(8*N*N, conn) # get bytes of A |
| 52 | A = np.frombuffer(Bytes, dtype=np.float64) |
| 53 | # could also do |
| 54 | # A = np.array(struct.unpack(f'{N*N}d', Bytes)) |
| 55 | A = A.reshape(N,N) |
| 56 | print(f'received {N} x {N} from client') |
| 57 | inv = np.linalg.inv(A) |
| 58 | conn.send(inv.tobytes()) # send inv(A) |
| 59 | print(f'sent inverse to client') |
| 60 | except KeyboardInterrupt: |
| 61 | break |
| 62 | conn.close() |
| 63 | if __name__ == "__main__": main() |
no test coverage detected