Implement a simple chat application in Python

Assignment Help Python Programming
Reference no: EM132244592

Assignment Questions -

Question 1 - As part of this problem, you will implement a simple chat application in Python. A chat app will allow a user to type in a message from the keyboard and send that message to other (one or more) chat apps. The chat app will be using TCP sockets to communicate with each other. The code for the chat client should be saved in chat.py. The chat client may take the following command line arguments.

  • First argument: A string that identifies the name of the user running the chat program.
  • Second argument: A number indicating the port number on which the chat client will wait for incoming connections.
  • Remainder arguments: The remaining arguments are a list of strings that specify the IP address and port number of other chat clients to connect to. For example, the string 192.168.1.5:2000 indicates that the IP address is 192.168.1.5 and the port number is 2000.

As an example, to setup a conversation among three chat apps, you will need to start your chat app three times with the following arguments:

  • python chat.py user1 5001 127.0.0.1:5002 127.0.0.1:5003
  • python chat.py user2 5002 127.0.0.1:5001 127.0.0.1:5003
  • python chat.py user3 5002 127.0.0.1:5001

Under the above configuration, the messages typed by user 1 will be received by users 2 and 3. Similarly, the messages typed by user 2, will be received by users 1 and 3. However, the messages typed by user 3, will be received by user 1 but not user 3. When the user types "exit", the chat client will close opened all sockets and quit. As an important side note, the connections to the clients should be established only when the user types in the first message; otherwise, you will get errors since not all chat clients will be running.

The content of the messages exchanged between users will be specified in JSON. It should include the following information:

  • Sequence number (seq) - a unique identifier for the message send by a user starting from 0.
  • Source user (user) - the user name as supplied as the first argument to the chat app.
  • Message (message) - the actual message that the user typed in.

Below is an example of a message encoded in JSON: {"seq": 0, "user": "octav", "message": "hello"}

Question 2 - A limitation of the above chat app is that you need to know ahead of time the IP addresses and port numbers of the users that you want to communicate. As part of this question, we will refine the chat app to allow users to register with the chat server so that all the users that are registered will receive the messages. You will have to implement the chat client in chat5.py and the server in server5.py. The system will work as follows:

1. When it starts, the chat client will connect to the server and register.

2. When the user types in the message in a chat client, that client will send the message to the server. It is the job of the server to distribute it to all connected chat clients.

3. When the chat client stops, it will send a message to unsubscribe from the server. For this question, the chat client will only accept the following three arguments:

1. A string that identifies the name of the user running the chat program.

2. A number indicating the port number on which the chat client will wait for incoming connections.

3. The IP address and port number of the chat server.

The chat client and server may exchange three types of messages (serialized using JSON): subscribe, unsubscribe, and message. The subscribe/unsubscribe operations will have the following fields:

  • Operation (operation): Either subscribe or unsubscribe.
  • Client (client): The IP and port number of the client.

An example of a subscribe message from a client running on 127.0.0.1:5000 is shown below: {"operation": "subscribe", "client": "127.0.0.1:5000"}

A message typed into a client is delivered to the other clients in two parts: first, it is delivered to the sever and then, the server delivers it to other connected clients. Similar to question 1, the message will include the following fields:

  • Sequence number (seq) - a unique identifier for the message send by a user starting from 0.
  • User (user) - the user name as supplied as the first argument to the chat app.
  • Message (message) - the actual message that the user typed in.

The job of the server is to maintain a list of connected clients. In response to a subscribe message, the server should add the IP:port combination to the list of connected clients. After the registration is complete, the client will read input from the keyboard. Each provided line will be sent in a single chat message whose format is detailed below. When a chat client receives data from a peer chat client, it should display the received message.

Reference no: EM132244592

Questions Cloud

Identify and develop the talent within the organization : HRM532 List the Strengths, Weaknesses, Opportunities and Threats (SWOT) that could propel an organization toward the creation of a specific method.
Approach specific business issue in the workplace : You will compare how two companies, within the same industry (Walmart and Amazon) , approach a specific business issue in the workplace.
Welcome to model three handover : Elon Musk wasn’t smiling, when he said, “Welcome to Model 3 handover.” Through a single silver door, a few moments before, he had entered the room,
Advantages and disadvantages of limited liability company : What are the advantages and disadvantages of a limited liability company?
Implement a simple chat application in Python : You will implement a simple chat application in Python. The code for the chat client should be saved in chat.py
Create a project management roadmap for the client : Create a project management roadmap for the client with projected timelines. Discuss the costs associated with the implementation, justifying your claims.
Design and share information flow map for firm : Design and share an information flow map for a firm or department that you are familiar with
Regional distributor purchases discontinued appliances : A regional distributor purchases discontinued appliances from various suppliers and then sells them on demand to retailers in the region.
Determine the most challenging aspect of a physician role : In your opinion, determine the most challenging aspect of a physician's role as the administrator of a group practice. Justify your response.

Reviews

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd