Read data from socket and return it in JSON format
(sock, buf_len, echo=True, pretty=False)
| 24 | |
| 25 | |
| 26 | def read_socket(sock, buf_len, echo=True, pretty=False): |
| 27 | """ Read data from socket and return it in JSON format """ |
| 28 | reply = sock.recv(buf_len).decode() |
| 29 | try: |
| 30 | ret = json.loads(reply) |
| 31 | except json.JSONDecodeError: |
| 32 | print("Error in reply: ", reply) |
| 33 | sock.close() |
| 34 | raise |
| 35 | if echo: |
| 36 | indent = 2 if pretty else None |
| 37 | print(json.dumps(ret, indent=indent)) |
| 38 | return ret |
| 39 | |
| 40 | |
| 41 | def get_app_name(pid): |
no test coverage detected