-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrixserver.py
More file actions
27 lines (25 loc) · 760 Bytes
/
matrixserver.py
File metadata and controls
27 lines (25 loc) · 760 Bytes
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
27
import socket, sys, json
s = socket.socket()
host = socket.gethostname()
port = 3000
s.bind((host,port))
s.listen(5)
print("The server is now listening.... at host :",host," port :",port)
c,a = s.accept() # c=>socket , a=> address
while True:
data = c.recv(1024)
data = json.loads(data.decode())
matrix_a = data.get("a")
matrix_b = data.get("b")
rows = data.get("c")
column = data.get("d")
result=[[0 for i in range(column)] for i in range(rows)]
for i in range(rows):
for j in range(column):
result[i][j] = matrix_a[i][j]+matrix_b[i][j]
print("The Sum of received two Matrices is : ")
for r in result:
print(r)
response = json.dumps({"response":result})
c.send(response)
c.close()