org.jnetstream.capture
Class RemoteServer

java.lang.Object
  extended by org.jnetstream.capture.RemoteServer

public class RemoteServer
extends java.lang.Object

Allows remote capture sessions to be started from non-local system. The remote server listens for incomming client network connections on a network socket and after proper authentication opens up remote sessions with the clients. The RemoteServer also provides several methods that can be used on the client side for establishing a remote session with a running server on a remote system. Once a RemoteSession is created it can be used to do nearly everything that is possible as it all operations were local. The speed of the operations has to be taken into account as all operations are transmitted accross the network, in a client/server environment, including packet buffer data, which may take considerably longer then if the same operation was done using a local session created using Captures methods.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Constructor Summary
protected RemoteServer()
           
  RemoteServer(byte[] authentication)
          Creates a remote server that listens on the default port for incomming connections and establishes RemoteSessions.
  RemoteServer(byte[] authentication, RemoteSession.RemoteSessionFactory handler)
          Creates a remote server that listens on the default port for incomming connections and establishes RemoteSessions.
 
Method Summary
 void close()
          Closes this remote server down and will stop listenting for any more incomming connections.
 void listen()
          Listens on a network server socket for incomming connections.
static RemoteSession openSession(java.net.URI uri)
          Creates an unauthenticated, but connected session to the remote server.
static RemoteSession openSession(java.net.URI uri, byte[] authentication)
          Creates an empty, but connected session to the remote server.
protected  void setHandler(RemoteSession.RemoteSessionFactory handler)
          Changes the default handler which handles the incomming connection requests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RemoteServer

protected RemoteServer()

RemoteServer

public RemoteServer(byte[] authentication)
             throws java.io.IOException
Creates a remote server that listens on the default port for incomming connections and establishes RemoteSessions. The server is initialized with the specified authentication byte pattern that must be supplied by the remote end inorder to authenticate its connection.

Parameters:
authentication - authentication pattern that all remote clients will have to authenticate against
Throws:
java.io.IOException

RemoteServer

public RemoteServer(byte[] authentication,
                    RemoteSession.RemoteSessionFactory handler)
             throws java.io.IOException
Creates a remote server that listens on the default port for incomming connections and establishes RemoteSessions. The server is initialized with the specified authentication byte pattern that must be supplied by the remote end inorder to authenticate its connection.

Parameters:
authentication - authentication pattern that all remote clients will have to authenticate against
handler - a custom handler that is registered to handle the work
Throws:
java.io.IOException - any IO errors
Method Detail

setHandler

protected void setHandler(RemoteSession.RemoteSessionFactory handler)
Changes the default handler which handles the incomming connection requests.

Parameters:
handler - user supplied handler to handling incomming connections

listen

public void listen()
            throws java.io.IOException
Listens on a network server socket for incomming connections. All connections are handed off to the handler for processing and authentication.

Throws:
java.io.IOException - any IO errors

close

public void close()
           throws java.io.IOException
Closes this remote server down and will stop listenting for any more incomming connections. Any existing connections are also shutdown.

Throws:
java.io.IOException - any IO errors

openSession

public static RemoteSession openSession(java.net.URI uri)
                                 throws java.io.IOException,
                                        RemoteAuthenticationException
Creates an unauthenticated, but connected session to the remote server. At that point any of the RemoteSession commands can be invoked and new remote captures started. If the server requires authentication the connection will fail and RemoteAuthenticationException will be thrown.

Parameters:
server - server to connect to
authentication - authentication parameter used to authenticate the remote session
Returns:
a connected remote session to the remote server
Throws:
RemoteAuthenticationException - if the server requires remote authentication this method will always throw this exception
java.io.IOException

openSession

public static RemoteSession openSession(java.net.URI uri,
                                        byte[] authentication)
                                 throws java.io.IOException,
                                        RemoteAuthenticationException

Creates an empty, but connected session to the remote server. At that point any of the RemoteSession commands can be invoked and new remote captures started. Here is a short example:

 RemoteSession session = RemoteServer.openSession(new URI("192.168.1.100"));
 LiveCapture capture = session.openLive();
 
 while (capture.hasNext()) {
   System.out.println("Got a packet=" + capture.next().toString());
 }
 
 session.close(); // Closes down everything
 

If the supplied authentication byte pattern does not authenticate the remote session correctly, RemoteAuthenticationException will be thrown.

Parameters:
server - server to connect to
port - use the specified port instead of the default remote session port
authentication - authentication parameter used to authenticate the remote session
Returns:
a connected remote session to the remote server
Throws:
RemoteAuthenticationException - if the authentication fails with the server
java.io.IOException