Question: Please create a python program for a chat room. Below are the predefined Client and Server programs. The program should use these prefined Client and

Please create a python program for a chat room. Below are the predefined Client and Server programs. The program should use these prefined Client and Server programs to make a chat room.

Client.py

# Python program to implement client side of chat room. import socket import select import sys from thread import * server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if len(sys.argv) != 3: print "Correct usage: script, IP address, port number" exit() IP_address = str(sys.argv[1]) Port = int(sys.argv[2]) try: server.connect((IP_address, Port)) print "Connected" except: print "Failed to connect" while True: # maintains a list of possible input streams sockets_list = [sys.stdin, server] read_sockets,write_socket, error_socket = select.select(sockets_list,[],[]) server.close()

#Done

Server.py

# Python program to implement server side of chat room. import socket import select import sys from thread import * server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # checks whether sufficient arguments have been provided if len(sys.argv) != 3: print "Correct usage: script, IP address, port number" exit() # takes the first argument from command prompt as IP address IP_address = str(sys.argv[1]) # takes second argument from command prompt as port number Port = int(sys.argv[2]) server.bind((IP_address, Port)) server.listen(100) list_of_clients = {} while True: conn, addr = server.accept() print addr[0] + " connected" conn.close() server.close()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!