Skip to content

Instantly share code, notes, and snippets.

@TheProjectsGuy
Created July 1, 2019 12:18
Show Gist options
  • Select an option

  • Save TheProjectsGuy/476cc615adbc0b4737b2e8617a3c16c5 to your computer and use it in GitHub Desktop.

Select an option

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.
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