DPSD HW5 - Phase 2

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.

  1. Create a package called server.
  2. Create a new interface called PizzeriaInterface which will be implemented by PizzeriaServer.
  3. 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!).
  4. Your Server must communicate with the Clients via a socket connection using Object Serialization.
  5. Your Server must support multiple Clients at the same time.
  6. Your Server must implement the protocol you have designed.
  7. Your Server will provide access to a single instance of your API to allow clients to manipulate the Pizzerias.
  8. Design your Server to demonstration separation of concerns and loose coupling.
  9. In other words, your Server class does NOT do all of this directly!
Create your Real Client
  1. Remove Test Client code that calls into the API.
  2. Write your Real Client to use messages sent via a socket connection (using serialization) to your Server.
  3. Make sure neither your Client code nor your UI nor your GUI references any of your API code.
  4. 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.
  5. The messages to the Server must follow your Protocol.
  6. The messages to the Server must be sent/received via Object Serializaion.
  7. 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:

  1. 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.

  2. 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.

  3. 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.

  4. Tip: Make sure your design supports uploading multiple pizzerias from multiple clients and that your UI supports this feature.

  5. 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.

  6. 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?

  7. 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());