Last active
July 3, 2019 09:59
-
-
Save TheProjectsGuy/381624be1e23d43299b1b7b3c2b42253 to your computer and use it in GitHub Desktop.
A dummy client through which you can send and receive data. Built using socket programming in Python 3.5.
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
| import socket | |
| IP_ADDR = "127.0.0.1" | |
| SOCKET_PORT = 5000 | |
| with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as skt: | |
| skt.connect((IP_ADDR, SOCKET_PORT)) | |
| while True: | |
| usr_ch = input("Send or receive [s/r]? (0 to exit): ") | |
| if usr_ch == 's': | |
| # Send something | |
| send_msg = input("Enter message to send: ") | |
| send_msg = bytes(send_msg, "utf-8") | |
| skt.sendall(send_msg) | |
| elif usr_ch == 'r': | |
| # Receive data | |
| recv_msg = skt.recv(1024) | |
| recv_msg = str(recv_msg, "utf-8") | |
| print("Received: %s" % (recv_msg, )) | |
| elif usr_ch == '0': | |
| break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment