-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39393c7
commit ed7964e
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/python3.6 | ||
# Simple implementation based on the book Listing 14.3 | ||
|
||
from socketserver import TCPServer, StreamRequestHandler | ||
|
||
class ClientHandler(StreamRequestHandler): | ||
def handle(self): | ||
addr = self.request.getpeername() | ||
msg_to_client = 'Thank you for connecting to basic SocketServer' | ||
print('Got connection from', addr) | ||
self.wfile.write(bytes(msg_to_client, 'utf-8')) | ||
|
||
listening_port = 1234 | ||
try: | ||
socket_server = TCPServer(('', listening_port), ClientHandler) | ||
print("Simple socketServer started, listening on port ",listening_port) | ||
print("...[stop by Ctrl+C]") | ||
socket_server.serve_forever() | ||
except Exception as setuper: | ||
print(" Could not start server, due to :", setuper) | ||
except KeyboardInterrupt: | ||
print("Server was stopped by a Ctrl+C. Exiting program") |