Allows multi-clients to connect to server, subscribe and tweet messages with hashtags
High Level Description of Implementation Idea
-
Client:
- Client will have 2 threads: main thread takes user's input and processes commands, the other thread (client listener) keeps listening to the server to receive new messages (if there is new message with hashtags that client has subscribed).
- When connecting to the server, the client will create a client listener which sends sign-in request to server. If sign-in successful, client listener will keep listening to that socket connection to receive messages from the server. Then client will create another socket connection to send request to server with new user's command input.
- Client saves all messages receive from server. Those messages can be retrieved with command
timeline - All the input arguments will be checked before processing the commands.
- The client will clean up all data before exiting.
-
Server:
- When client first signs in, if there is no existing username => client logins successfully. The server will save the socket connection to broadcast messages later.
- Whenever accepting a new connection, server creates a new thread to handle that client.
- If server receives a new tweet, it will broadcast the message to all subscribers by using saved socket connection (server saved them when clients first signed in)
- The server will clean up all data before exiting.
- Require
Python >= 3.6 Version - Download or git clone the project
- Clone this repo to your local machine using
https://github.com/nhat-lan/networking.git
update and install this Python 3 version
$ brew update && upgrade
$ brew install python3Users can send tweet with one or multiple hashtags, get all messages receive from server (messages related to hashtags that user subscribed to), retrieve online users list, subscribe hashtag, unsubscribe hashtag.
Move to the top directory of the project.
Running Server:
$ python3 ttweetser.py <portnumber>Running Clients:
$ python3 ttweetcli.py <serverip> <portnumber> <username>Client can use commands such as tweet, subscribe, unsubscribe, timeline, getusers, exit.
tweet "<message>" <hashtag>
$ tweet "Here is my mesage" #myhashtag1
$ tweet "Here is my mesage" #myhashtag#anotherHashTagsubscribe <hashtag>
$ subscribe #myhashtag1
$ subscribe #ALLunsubscribe <hashtag>
$ unsubscribe #myhashtag1
$ unsubscribe #ALLtimeline
$ timelinegetusers
$ getusersexit
$ exitNote:
- Server IP: `0.0.0.0` or `127.0.0.1`
- Message format:
+ Message is always between `""`, within range [1,150] characters
- Hashtag format:
+ Hashtag is within range [1,] not included `#`, can only included alphanumeric characters ([a-zA-Z0-9])
+ Hashtag #ALL is reserved, so client cannot tweet with this hashtag
- Username format:
+ Can only included alphanumeric characters ([a-zA-Z0-9])
- Subscribe:
+ Client can only subscribe one hashtag at a time
+ Clients can only subscribe up to 3 hashtag (unless unsubscribe previous subscribed hashtags)
- Client will be removed from server when exiting. Server only store active clients.
- work was allocated equally between all team members
-
Option 1
- 🍴 Fork this repo!
-
Option 2
- 👯 Clone this repo to your local machine using
https://github.com/nhat-lan/networking.git
- 👯 Clone this repo to your local machine using
- HACK AWAY! 🔨🔨🔨
- 🔃 Create a new pull request using
https://github.com/nhat-lan/networking/compare/.
Nhat Lan Le Tu
Uyen Dinh
Kiet Tran
Please reach out to our team!