Skip to content

Instantly share code, notes, and snippets.

@a-recknagel
Created March 25, 2021 22:28
Show Gist options
  • Save a-recknagel/2a387db2e034d76ebaf0d3a6c13ebc36 to your computer and use it in GitHub Desktop.
Save a-recknagel/2a387db2e034d76ebaf0d3a6c13ebc36 to your computer and use it in GitHub Desktop.
Simple socket communication
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(('0.0.0.0', 5000))
s.send(b'Hello, world\r\n')
print(f"Received {s.recv(1024)}")
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('0.0.0.0', 5000))
s.listen()
while True:
conn, _ = s.accept()
with conn:
print(f"Got {conn.recv(1024)}")
conn.send(b"Thanks!")
@a-recknagel
Copy link
Author

ubuntu -> "Hello, World!"
windows ->

Traceback (most recent call last):
  File "C:/Users/me/PycharmProjects//serve.py", line 4, in <module>
    s.connect(('0.0.0.0', 5000))
OSError: [WinError 10049] The requested address is not valid in its context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment