omnisockets
Class OmniListener

java.lang.Object
  |
  +--omnisockets.OmniListener
All Implemented Interfaces:
java.lang.Runnable

public class OmniListener
extends java.lang.Object
implements java.lang.Runnable

The OmniListener is a server socket that runs itself in a thread, accepts connections, and notifies the application when a connection is made.

Since:
OmniSockets 1.0
Version:
1.0.beta.1, 10/31/2002
Author:
Richard Bockenek
See Also:
OmniSocket, OmniEventHandler

Constructor Summary
OmniListener(int port)
          Constructs an OmniListener on the specified port.
OmniListener(int port, int backlog)
          Constructs an OmniListener on the specified port with the specified backlog.
OmniListener(int port, int backlog, java.net.InetAddress bindaddr)
          Constructs an OmniListener on the specified port with the specified backlog and bindaddr.
OmniListener(int port, int backlog, java.net.InetAddress bindaddr, omnisockets.OmniEventHandler eventHandler)
          Constructs an OmniListener on the specified port with the specified backlog and bindaddr.
OmniListener(int port, int backlog, omnisockets.OmniEventHandler eventHandler)
          Constructs an OmniListener on the specified port with the specified backlog.
OmniListener(int port, omnisockets.OmniEventHandler eventHandler)
          Constructs an OmniListener on the specified port.
 
Method Summary
 omnisockets.OmniSocket accept()
          Accepts a connection synchronously.
 int getBacklog()
          Returns the backlog.
 java.net.InetAddress getBindAddr()
          Returns the bind address.
 omnisockets.OmniEventHandler getEventHandler()
          Returns the event handler.
 int getPort()
          Returns the port.
 java.net.ServerSocket getRawSocket()
          Returns the raw socket.
 java.lang.Thread getThread()
          Returns the thread.
 boolean isValid()
          Tests the valid state.
 void run()
          Accepts connections and notifies the user when a new connection is made.
 void setEventHandler(omnisockets.OmniEventHandler eventHandler)
          Sets the event handler.
 void setName(java.lang.String name)
          Sets the listener name.
 void setPriority(int priority)
          Sets the listener priority.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OmniListener

public OmniListener(int port)
             throws java.io.IOException
Constructs an OmniListener on the specified port.

Parameters:
port - the port number to use

OmniListener

public OmniListener(int port,
                    omnisockets.OmniEventHandler eventHandler)
             throws java.io.IOException
Constructs an OmniListener on the specified port.

Parameters:
port - the port number to use
eventHandler - the OmniEventHandler to run when a conection is established

OmniListener

public OmniListener(int port,
                    int backlog)
             throws java.io.IOException
Constructs an OmniListener on the specified port with the specified backlog.

Parameters:
port - the port number to use
backlog - the maximum number of connections to accept

OmniListener

public OmniListener(int port,
                    int backlog,
                    omnisockets.OmniEventHandler eventHandler)
             throws java.io.IOException
Constructs an OmniListener on the specified port with the specified backlog.

Parameters:
port - the port number to use
backlog - the maximum number of connections to accept
eventHandler - the OmniEventHandler to run when a conection is established

OmniListener

public OmniListener(int port,
                    int backlog,
                    java.net.InetAddress bindaddr)
             throws java.io.IOException
Constructs an OmniListener on the specified port with the specified backlog and bindaddr.

Parameters:
port - the port number to use
backlog - the maximum number of connections to accept
bindaddr - the bind address to use, or null to use the canonical network interface

OmniListener

public OmniListener(int port,
                    int backlog,
                    java.net.InetAddress bindaddr,
                    omnisockets.OmniEventHandler eventHandler)
             throws java.io.IOException
Constructs an OmniListener on the specified port with the specified backlog and bindaddr.

Parameters:
port - the port number to use
backlog - the maximum number of connections to accept
bindaddr - the bind address to use, or null to use the canonical network interface
eventHandler - the OmniEventHandler to run when a conection is established
Method Detail

run

public void run()
Accepts connections and notifies the user when a new connection is made.

Specified by:
run in interface java.lang.Runnable

accept

public omnisockets.OmniSocket accept()
                              throws java.io.IOException
Accepts a connection synchronously.

java.io.IOException

getBindAddr

public java.net.InetAddress getBindAddr()
Returns the bind address.


getPort

public int getPort()
Returns the port.


getBacklog

public int getBacklog()
Returns the backlog.


getEventHandler

public omnisockets.OmniEventHandler getEventHandler()
Returns the event handler.


setEventHandler

public void setEventHandler(omnisockets.OmniEventHandler eventHandler)
Sets the event handler. If previously there was no event handler, then a listener thread is created and started. If previously there was an event handler and it is now set to null, then the existing thread is set to invalid which will stop it next time through its accept loop.

Parameters:
eventHandler - an OmniEventHandler object useed to notify the user of socket events

isValid

public boolean isValid()
Tests the valid state.


setPriority

public void setPriority(int priority)
Sets the listener priority.

Parameters:
priority - a valid thread priority

setName

public void setName(java.lang.String name)
Sets the listener name.

Parameters:
name - a descriptive string

getThread

public java.lang.Thread getThread()
Returns the thread. The user may get this to set some thread option besides priority or name.


getRawSocket

public java.net.ServerSocket getRawSocket()
Returns the raw socket. The user may get this to set a server socket options that are not supported by OmniSocket directly.

Returns:
the java.net.Socket object