Created
July 1, 2019 12:18
-
-
Save TheProjectsGuy/476cc615adbc0b4737b2e8617a3c16c5 to your computer and use it in GitHub Desktop.
A simple socket client that will connect to a server, send "Hello World" and then end connection and terminate.
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 address and port of connection | |
| IP_ADDR = "127.0.0.1" | |
| PORT = 50001 | |
| with socket.socket( | |
| socket.AF_INET, socket.SOCK_STREAM | |
| ) as skt: | |
| # Connect to the IP_ADDR and PORT (server address) | |
| skt.connect((IP_ADDR, PORT)) | |
| # Connection done, send things | |
| skt.sendall(bytes("Hello World", "utf-8")) | |
| print("Sent message") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment