Create your Server
Before working on this step make sure you have learned the creation of Client/Server interaction
by reviewing the KnockKnock and Echo examples we covered in class.
- Create a package called server.
- Create a new interface called PizzeriaInterface which will be implemented by
PizzeriaServer.
- You will need to add methods in the Server interface based on the functionality
required by the clients you have so far (hint for the future!).
- Your Server must communicate with the Clients via a socket connection using Object Serialization.
- Your Server must support multiple Clients at the same time.
- Your Server must implement the protocol you have designed.
- Your Server will provide access to a single instance of your API to allow clients to manipulate
the Pizzerias.
- Design your Server to demonstration separation of concerns and loose coupling.
- In other words, your Server class does NOT do all of this directly!
Create your Real Client
- Remove Test Client code that calls into the API.
- Write your Real Client to use messages sent via a socket connection (using serialization) to your Server.
- Make sure neither your Client code nor your UI nor your GUI references any of your API code.
- The UI and the Client may however reference a PizzaConfig object that comes from the Server.
- The Client may only act as a pass-through and return the object to the caller.
- The UI will only use the object for printing and for configuring a Pizzeria.
- The GUI will NOT use a PizzaConfig object, although it could if you were fully implementing all usable features.
- The messages to the Server must follow your Protocol.
- The messages to the Server must be sent/received via Object Serializaion.
- Because this is a course, do not to implement a client/server version of reading from a text
file, but think about the issues involved if you were to implement that too.
Tips:
- Requirement: You can model your Client and Server code on KnockKnock and Echo, but
note that these are simple examples showing basic sockets programming - you need to implement a more
sophisticated system that is compatible with the design principles you have already been using for
this project.
- Challenge: Design and implement your client/server code so it could handle different protocols.
To do this, investigate and use the Strategy Pattern - you do not have to implement multiple
protocols, just design your client/server communication so it could support multiple
protocols and have your initial communication between the 2 set the protocol (the strategy) used by
the Server.
You might consider using the Factory Pattern to help. You may want to add a new package too.
Note: These are both fairly simple patterns, but this is a big tip for meeting the
requirement listed first in this section.
- Tip: Make sure that the properties file is read in on the client machine, the Properties object is sent to the server (via serialization), the object is parsed on the Server and then added to the list of Pizzerias.
- Tip: Make sure your design supports uploading multiple pizzerias from multiple clients and that your UI supports this feature.
- Tip: If you use multiple projects you may copy the common code into each.
For instance, your Client, Server, UI, and GUI all need the model code. Rather than requiring that you learn how to package it into re-useable libraries, which is the proper way for a production-grade system, you may copy the package into each project. Note that this means you will have to make changes multiple times if you need to fix anything after making the copies.
- Questions: Who exactly should read in the properties file? What exactly should the Client know? What exactly should the Server know? What exactly do your two User Interfaces know or not know? In other words, what are the repsonsibilities and areas of concern for each class and/or package?
- Code Snippet: You will need to setup the streams in your sockets code
for reading and writing to the socket with serialization using ObjectStreams rather than character-based reads and writes; it should be something like this ...
ObjectOutputStream out = new ObjectOutputStream(clientSocket.getOutputStream());
ObjectInputStream in = new ObjectInputStream(clientSocket.getInputStream());