程序代写代做代考 concurrency Java distributed system python data structure gui Ying Chen, yingc4, 633582

Ying Chen, yingc4, 633582
1. Abstract
In this project, I have built a chat system using java. This system is based on client-server architecture. I use TCP socket to communicate between client and server through agreed upon message format which is encoded using json. And I use multi-thread techniques in java to enable server to communicate with many clients at the same time and enable the client to read from user, send message to server and receive from server, output message to user at the same time. I also use java concurrency technique such as synchronised word to acquire and release lock and use it to keep from data of the server to be modified by different threads at the same time.
The system can let user send messages to each other, create chat room and get information about chat room and users. The system solves multiple common challenges encountered by distributed system. They are summarised as below.
2. Heterogeneity
I use agreed upon message formats and data types. The messages between server and client are encoded in json format, they each have a specific meaning. They adhere to the protocols defined by the application including chat protocol, identity change protocol, join room protocol and room contents message protocol.
We can easily change the implementation of server or client and they still work as long as they still adhere the protocol.
And the system is implemented in java, which can run on various operating systems.
3. Openness
The system defined a standard protocol for communicating between client and server, this allow others to develop new client side (for example client with GUI or even using a different language for example python), and the new client can talk to the server as long as it adhere to the protocol.
4. Security
The system only allows messages to go to the client that need to receive it. For example, a client send a message, only the clients who are the in the same chat room can receive it, thus it ensures confidentiality. And it only allows the owner of a room to delete it. The system does so by recording the owner of a room, and when it receive request to delete a room, it will verify whether the owner sent the request. But the system doesn’t encrypted the message and nor it uses password, thus it has potential vulnerability.
5. Scalability
The server can handle multiple connections at same time. When a new client connects to it, it creates a new client to handle it. Thus the resources needed by the threads to handle the connection are linear with regard to the number of clients.
6. Failure Handling
If client gets disconnected, the server will remove the client from chat room and inform other clients and set the room ownership properly. The server side can detect this by test whether return value of read from socket. If server shuts down, the client can use the same method to detect that the connection is closed, and it will inform the user and exit.
And both the client and server will verify whe message received is valid, if it is not, it will ignore it and it will only repond to valid message defined by the protocols.
If the command is valid, but the action to performed is not valid, the server will send message to the client to indicate failure. For example, if the user asks the server to change its idenity, but the identity is already used by others, the server will refuse to change the identity and information this to the client, the client then will ouput messages to the user. The server and client adopt similar ways to handle other kind of failure of action, such as create room that already exists, a client who is not the owner to ask the server to delete the room or kick other client in the room, and ask to enter a room from which the client is just kicked out.
7. Concurrency
In this system, every connection with a client is handled by a thread in server. If multiple clients modify the data at the same time, there may be problem. For example, client1 adds chat room1 and client2 add chat room2 at the same time. If there is no synchronization, the result could be only room1 or room2 added to the chat rooms data structure. For a chat system that has many users online, this scenario is quite likely, so we must solve this problem.
In java, an object has an intrinsic lock, at the start of the code section denoted by synchronised keyword, the code attempted to acquire the intrinsic lock and after it finished the code section, it automatically release the lock. If one thread is in the code section, other thread must wait outside the section to acquire the lock that has been already acquired by thread in the code section, only when the thread in the code section finish the code section, other threads can enter the code section. So to
Chat Room Report


prevent from the data modified by more than one thread at the same time, we only need to add synchronised word to code sections that modified the data.
I use synchronized keyword to ensure the data structure can only modified by one thread at a time. The synchronized keyword is only used when receiving a message that will modify the data of the server.
8. Transparency
The users only need to know how to use the client. And they don’t have to know how the system works. And the application developer for the client only need to know the protocols and also don’t need to know the concrete implementation of the server.
9. Multi-server architecture
I will use a proxy server, it will allocate server for the client and make sure every server’s load are approximately same. Every server will have the information will the clients connected to it and all the chat room’s information. When one server’s chat room information has changed, it will send the updated information to other servers, so other servers will update theirs. A server will hand the message passing of the clients connected to it, if a message should be sent to a client that connected to another server, the server will send appropriate message to that server. The client will be changed, so that it first connect to the proxy server, then it connected to the server allocated by the proxy server.
10. Conclusion
In conclusion, I have learned a lot things such as network programming, multi-threading, monitor lock and synchronization, error handling and json format through this project. In the end, I successfully create a chat system that fulfilled the requirements by this project. But there is still large space for improvement. For example, the system can use encryption technique to encrypted messages and password to improve the security of this system. The client can have GUI interface to be more user friendly and the server side can adopt multi-server architecture to improve scalability.