Created
October 3, 2016 15:31
-
-
Save mikekwright/176f6e8a24690b25af89fd7d610b465c to your computer and use it in GitHub Desktop.
Sample client I created to validate the client-server hacker-rank problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import sys, threading, socket | |
| def read_all_from_connection(connection): | |
| raw_message = [] | |
| message = '' | |
| while 1: | |
| data = connection.recv(1024) | |
| if not data or data == '': | |
| break | |
| raw_message.append(data) | |
| messgae = b''.join(raw_message).decode() | |
| if 'END' in message: | |
| break | |
| return b''.join(raw_message).decode() | |
| def send_stdin(connection): | |
| lines = sys.stdin.readlines() | |
| for line in lines: | |
| # connection.send((line + '\n').encode()) | |
| connection.send(line.encode()) | |
| if __name__ == '__main__': | |
| sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
| sock.connect('./socket') | |
| send_stdin(sock) | |
| result = read_all_from_connection(sock) | |
| print(result) | |
| sock.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment