Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+ Who do you think is right? Why?

Answered: 1 week ago