Last active
April 8, 2020 18:15
-
-
Save MindPatch/0c88167d777ae529bd0e120cd2ca25fc to your computer and use it in GitHub Desktop.
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 socket | |
| from threading import Thread | |
| # Config | |
| #------------ | |
| host = 'localhost' | |
| port = 4649 | |
| #------------ | |
| s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) | |
| s.connect((host,port)) | |
| print(f'Connecting to | {host}:{port}') | |
| def get_msg(s): | |
| while True: | |
| print('\nMessage :> '+s.recv(1024).decode('utf-8')+'\n') | |
| def sent_msg(s): | |
| while True: | |
| s.send('\n'.encode('utf-8')+input().encode("utf-8")+'\n'.encode('utf-8')) | |
| if __name__ == '__main__': | |
| p1 = Thread(target=get_msg,args=(s,)) | |
| p2 = Thread(target=sent_msg,args=(s,)) | |
| p1.daemon = True | |
| p2.daemon = False | |
| p1.start() | |
| p2.start() | |
| # by : @knassar702 |
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 socket | |
| from threading import Thread | |
| # Config | |
| #------------ | |
| host = 'localhost' | |
| port = 4649 | |
| #------------ | |
| s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) | |
| s.bind((host,port)) | |
| s.listen(0) | |
| print(f'Starting on | {host}:{port}') | |
| def get_msg(s): | |
| while True: | |
| print('\nMessage :> '+s.recv(1024).decode('utf-8')+'\n') | |
| def sent_msg(s): | |
| while True: | |
| s.send('\n'.encode('utf-8')+input().encode("utf-8")+'\n'.encode('utf-8')) | |
| if __name__ == '__main__': | |
| while True: | |
| d , _ = s.accept() | |
| p1 = Thread(target=get_msg,args=(d,)) | |
| p2 = Thread(target=sent_msg,args=(d,)) | |
| p1.daemon = True | |
| p2.daemon = True | |
| p1.start() | |
| p2.start() | |
| # by : @knassar702 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment