Skip to content

Commit 6211929

Browse files
committed
basic client-server implementation
1 parent ca5c6f2 commit 6211929

File tree

4 files changed

+41
-43
lines changed

4 files changed

+41
-43
lines changed

server.py

-43
This file was deleted.

simple-client-server/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# simple client server
2+
3+
#### Note:
4+
- Run **`server.py`** first.
5+
- Now, run **`client.py`**.
6+
- verify the output.

simple-client-server/client.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# client.py
2+
3+
import socket
4+
5+
HOST, PORT = '127.0.0.1', 1400
6+
7+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
8+
s.connect((HOST, PORT))
9+
10+
s.send(b'Hello World')
11+
data = s.recv(1024)
12+
13+
s.close()
14+
print(repr(data.decode('ascii')))

simple-client-server/server.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# server.py
2+
3+
import socket
4+
5+
HOST, PORT = '127.0.0.1', 1400
6+
7+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
8+
s.bind((HOST, PORT))
9+
s.listen(1)
10+
11+
conn, addr = s.accept()
12+
13+
print('connected to:', addr)
14+
15+
while 1:
16+
data = conn.recv(1024)
17+
if not data:
18+
break
19+
conn.send(data + b' [ addition by server ]')
20+
21+
conn.close()

0 commit comments

Comments
 (0)