University of Cincinnati logo and link  
Making the Server Class
 
  UC ingotA full chat program will have client classes that is installed on our PCs send messages to a server, or controller class on one computer.  This controller class will then broadcast the messages back out to the clients.
    • Given this two way communication, this is more of a peer-to-peer network than a client-server network.  Each client acts as a server, and the server acts as a client, when it broadcasts messages to the clients.
    • That may be a shake too complex for our first application, so let's just make a bulletin board program to start.  In this program, the clients will post messages to the server, which will simply display them in a bulletin-board manner.  We can easily extend this later to be a full fledged chat application.
  • Our class must extend UnicastRemoteObject, and implement our interface Chat.  Once we implement the interface, we must provide implementations for each of the methods.
    • public void Login (String user, String password) Authenticate the user.  We could use some type of file, perhaps encrypted, to do this.  Or we could connect to a database and query the username and password against that.  Time permitting, we'll do that.  But for now, let's simply compare the user and password to some hardcoded values.
    • public void sendMessage(String message, String user) The message is what we want to display on the bulletin board.  Once we make a full chat program, we can direct the message to a specific user.  But for now, let's just add messages to a JList when the user equals "board".
 About UnicastRemoteObject