Implementation of a Protocol for Server/Client communication

Posted on 2007-09-29
Last Modified: 2013-11-23
I am trying to program a Server/Client application in which I have to implement a protocol for them to communicate. The server is supposed to load an address book from a file, and then allow the client to add/delete from it.  I have the server and client classes and I created a protocol class that recognizes the messages from the client, but I am a little confused on the correct way to do the add/delete to the file.  The way that I am structuring it is that the client sends a command to the server, the server then passes this message to a method in the protocol class.  The server also loads the file when it starts.  So is the correct process then to just return a value from the protocol indicating the type of command for the server to do on the file, and then proceed from there?  I don;t think the protocol class should write to the file, but I am a little confused on which class should write to the file.  Thank you!
Question by:eric68
    1 Comment
    LVL 14

    Accepted Solution

    I would delegate the I/O work to a "persistence manager" class implementing a generic I/O interface. This makes it easier to modify the persistence method without changing server/protocol code. For example, you might later decide to store the address book in a database rather than a file. In this case you will only need to create and instantiate a new class implementing the generic I/O interface, and use it in place of the filesystem I/O class. You can instantiate your I/O classes by creating a factory class that will return an instance of a persistence manager of a specific type that is provided as a parameter to the Factory.getInstance() method.


      Nayer Naguib

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Live - One-on-One Java Help from Top Experts

    Solve your toughest problems, fast.
    Java experts are online now and ready to help you.

    Suggested Solutions

    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now