I have recently decided to try and learn how to use java Sockets for client/server communication, as well as swing and threads, etc. and have (pretty much) completed a small client server application.
The application is basically a syntax-highlighting notepad, a client swing GUI which connects to a (multi-threaded) server which handles data being sent to each client.
The main function of the program is turn-based code editing:
- Client 1 Connects to Server
- Client 2 Connects to Server
- Client 1 requests Control of the program Lock
- Client 1 edits the source, and then clicks "send data"
- On sending, client 1 relinquishes the lock, and the new data is sent to every other connected client
- Client 2 requests control, edits, etc.
The server takes connections, then creates a new thread to deal with each. The thread will read and write from/to the Clients. All threads of this type will be passed the shared "Lock" object.
There is more functionality I could add, like a notification that the lock is free, or a waiting queue, but I am more concerned with the possibility that the code I have produced is bad practice, or not structured very well.
I am not a new programmer, but I am still very inexperienced as i have only learnt in bits through academia, and am only now starting to pursue private projects.
I would really appreciate some constructive criticism, and my main areas of concern are:
- The way Messages are passed between Client/Server (Lack of proper protocol)
- Threading (poor use of synchronized methods)
- General Code Structure/practice
- Incorrect use of Sockets and Socket I/O
Be gentle, this is my first ever completed project :')