File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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} " )
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments