I use python 3.7.9 for this assignment
there is a file called credential.txt, which is used for Authentication
the struct is
username1 password1
username2 password2
there is a file called userData.json
it records the offline message, blacklist, start time, end time and it's IP and port number
Every we set up a new server ,userData.json
file will be renewed
the struct is
"username": {
"message": ["", ""],
"blackList": ["", ""],
"active_period": [
{
"start":
"end":
}
],
"clientAddress": [IP, port]
}
The server will record
- users be blocked
- online user
- client threads
- port been used
The server can
- Authentication
- Message
- Notifications
- Find users online
- Find online history
- show Blacklist to client
client is responsible to receive data from server and communicate with user
Client have two thread
- input thread
this thread keeps listening to the user's input,
when the thread receive a input, it will respond to server or to a p2p-connection client
- receive thread
this thread keeps listening to the server
each p2p connection is connected, then there will have one more thread which keeps listening to the p2p-connection client
-
set up server
-
set up client
you can have multiple user
-
when you want to create a p2p connection, remember to input the
yes
orno
the other system design is similar to the assignment specification
- in the
credentials.txt
there may have some test user name and password, delete it before test - logout broadcast in private not finish
- sometime there will have some json error, it happens rarely(I don't know it still exists or not)
-
server
- sending:
- by
clientsocket.send()
- it will auto reply to the client's message
- by
- receiving:
- by
clientsocket.recv(1024)
- it will split the receiver's data by
<space>
, it will keep tracking the first keyword, and do the corresponding reply
- by
- sending:
-
client
-
sending:
-
-
by
clientsocket.send()
-
it will send message corresponding to user input to the server
-
it will read the input from user and auto communication with server
-
-
receiving:
- by
clientsocket.recv(1024)
- receive user input
- receive server reply
- by
-
-
the server keeps accepting new client, create a new thread when a new client connected,
and the server will auto reply to clients
-
Then the server will do Authentication with client
-
Then client will create two thread for receiving message from server and for receiving input from the user
- the thread listen to user will detect
Peer to peer Messaging(private()) and stopprivate()
- the thread listen to server will detect
startprivate()
- the thread listen to user will detect
-
the client will ask the server for the offline message
-
the client will tell server to broadcast the presence
-
message exchanging start
the square is client1 who want to start a p2p connection with triangle (client 2)
the circle is server
When the triangle receive [request]
, a global variable privateMessage
will be changed in ReceiveServer(Thread)
, it will tell InputThread(Thread)
to receive a yes/no