Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import sys
- HOST = '' # Symbolic name meaning all available interfaces
- PORT = 25565 # Arbitrary non-privileged port
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.bind((HOST, PORT))
- s.listen(5)
- print("Welcome to ChatSrv use /exit to quit and (usr) to view the name of the other user.")
- print("Server Started.")
- usrnme = raw_input("Enter a username: ")
- conn, addr = s.accept()
- print addr, " Joined. Waiting for MetaData."
- ClientUsr = conn.recv(1024)
- print "Client Username:", ClientUsr
- conn.sendall(usrnme)
- while 1:
- #Send a message
- a = raw_input("Message to Send: ")
- if a == "/exit":
- print("Prepearing to close down.")
- conn.sendall("EXIT")
- conn.close()
- sys.exit("--END--")
- """if a == "/changename":
- usrnme = raw_input("New username: ")
- conn.sendall("newName")
- conn.sendall(usrnme)"""
- conn.sendall(usrnme + ": " + a)
- #Recieve a message.
- data = conn.recv(1024)
- if data == "EXIT":
- print("The Server has closed the connection.")
- conn.close()
- sys.exit("The chat server has been closed by the remote server")
- print(data)
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment