def server():
import socket
s = socket.socket(AF_INET, SOCK_STREAM)
x = socket.gethostname()
host = socket.gethostbyname(x)
print(" server will start on host : ", host)
port = 1024
s.bind((host,port))
print("")
print(" Server done binding to host and port successfully")
print("")
print("Server is waiting for incoming connections")
print("")
s.listen(1)
conn, addr = s.accept()
print(addr, " Has connected to the server and is now online ...")
print("")
while 1:
message = input(str(">> "))
message = message.encode()
conn.send(message)
print("message has been sent...")
print("")
incoming_message = conn.recv(1024)
incoming_message = incoming_message.decode()
print(" Client : ", incoming_message)
print("")
def client():
import socket
from socket import AF_INET, SOCK_STREAM
x = socket.gethostname()
info = socket.gethostbyname(x)
print("yours user is: " + info)
s = socket.socket(AF_INET, SOCK_STREAM)
host = input(str("Please enter the hostname of the server : "))
port = 1024
s.connect((host,port))
print(" Connected to chat server")
while 1:
incoming_message = s.recv(1024)
incoming_message = incoming_message.decode()
print(" Server : ", incoming_message)
print("")
message = input(str(">> "))
message = message.encode()
s.send(message)
print("message has been sent...")
print("")