Skip to content

Commit 29143f0

Browse files
committed
Add "Simple Server" example
Signed-off-by: Ercan Ersoy <ercanersoy@ercanersoy.net>
1 parent c8b906f commit 29143f0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

simple-server/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Simple Server
2+
3+
A simple server program
4+
5+
This example is giving information.

simple-server/simple-server.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import socket
2+
import sys
3+
4+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server:
5+
server.bind(("", 23))
6+
7+
server.listen(1)
8+
9+
print("The server has been started.")
10+
11+
connection, address = server.accept()
12+
13+
with connection:
14+
print("A client has been connected.")
15+
16+
connection.sendall(b"Hello, World!\n")
17+
18+
while True:
19+
string = connection.recv(1)
20+
21+
connection.close()
22+
print("A connection closed.")
23+
24+
sys.exit()

0 commit comments

Comments
 (0)