Created
March 25, 2021 22:28
-
-
Save a-recknagel/2a387db2e034d76ebaf0d3a6c13ebc36 to your computer and use it in GitHub Desktop.
Simple socket communication
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 | |
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)}") |
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 | |
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!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ubuntu -> "Hello, World!"
windows ->