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
802 B

import socket
from time import sleep
class EchoClient:
HOST = '' # The server's hostname or IP address
PORT = 65432 # The port used by the server
def __init__(self, host=HOST, port=PORT):
self._s = socket.socket()
self._s.connect((host, port))
print("Client initialized.")
def echo(self, message="Hello World!"):
print("Client will send data: '{}'".format(message))
data = self._s.recv(4096)
response = data.decode()
print("Client received data from server: {}".format(response))
if message == "!quit":
print("Client terminating.")
return repr(response)
def close(self):