"""Terian made a really simple chat client""" #currently only functional between 1 server, 1 client #currently not multithreaded #currently only sends/receives up to 100 bytes import socket import sys from threading import Thread #to be used once I am capable of it def serve(port): """attempts to open a socket through port, listens for clients, chats.""" s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((socket.gethostname(), port)) s.listen(5) (s2, address) = s.accept() chat(s2) s.close() s2.close() def client(host, port): """client method attempts to connect to host via port, chats.""" s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) chat(s) s.close() def chat(socket1): """sends and receives messages up to 100 bytes through socket1""" print("Enter a message, send empty message to end.") while(True): astr = input("Self: ") socket1.send(astr.encode()) if(astr == ""): print("Ended chat\n") return received = socket1.recv(100).decode() if(received == ""): print("Chat was ended\n") return print("Other guy: " + received)