Skip to content

Commit 79ecb4e

Browse files
committed
Frist Files
0 parents  commit 79ecb4e

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# echo-client.py
2+
3+
import socket
4+
5+
HOST = "127.0.0.1" # The server's hostname or IP address
6+
PORT = 65432 # The port used by the server
7+
8+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
9+
s.connect((HOST, PORT))
10+
s.sendall(b"Hello, world")
11+
data = s.recv(1024)
12+
13+
print(f"Received {data!r}")

server.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# echo-server.py
2+
3+
import socket
4+
5+
HOST = "127.0.0.1" # Standard loopback interface address (localhost)
6+
PORT = 65432 # Port to listen on (non-privileged ports are > 1023)
7+
8+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
9+
s.bind((HOST, PORT))
10+
s.listen()
11+
conn, addr = s.accept()
12+
with conn:
13+
print(f"Connected by {addr}")
14+
while True:
15+
data = conn.recv(1024)
16+
if not data:
17+
break
18+
conn.sendall(data)

0 commit comments

Comments
 (0)