An attempt at working the TCP sockets in python.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
1018 B

import socket
class EchoServer:
HOST = '' # Standard loopback interface address (localhost)
PORT = 65432 # Port to listen on (non-privileged ports are > 1023)
def __init__(self, host=HOST, port=PORT):
self._host = host
self._port = port
print("Server Initializing on Host({0}) and Port({1})".format(self._host, self._port))
sock = socket.socket()
sock.bind((self._host, self._port))
print("Server Listener initialized")
conn, addr = sock.accept()
print('Server Connection From Client:', addr)
while True:
data = conn.recv(4096).decode()
print("Server received data from client {0}: {1}".format(str(addr), str(data)))
if data == "!quit":
print("Server Terminating")
response = "Received: " + data