HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"A Generic Client/Server Architecture for Java"
Volume: 5 Issue: 1, p.70

	

Listing 1:

Channel channel = new Channel(new SockDevice(hostname, port));
public class MyErrorListener
{
    public void recv(ChannelMsg msg)
    {
         Error e = (Error)msg.getData();
         System.err.println(e.getErrorString());
        // do something with the error!
    }
}
Channel.registerListener(Error.class, new MyErrorListener());
channel.waitForClients(true);

Listing 2:

while (true)
{
    // Wait for a server
    while (channel.getCurrentDevice().isDeviceOk() == false)
    {
        try
        {
            channel.waitForMsgs(false);
        }
        catch (Exception e)
        {
            Log.println("server not there");
            try { Thread.sleep(2000); } catch (Exception ee) {}
        }
    }
    try
    {
        channel.send(new Command("status"));
    }
    catch (Exception e)
    {
     // Problems? Go back and wait for server
        break;
    }
    if (channel.getCurrentDevice().isDeviceOk() == false) break;
}


 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.