|
IP*Works! V9 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectipworks.Ipdaemon
public class Ipdaemon
The IPDaemon Bean is used to create TCP/IP servers. The bean handles multiple simultaneous connections on the same TCP/IP port (service port). It is designed to balance the load between connections for a fast, powerful server.
IPDaemon is the server complement of IPPort (which is used to create client applications). They share a common design philosophy and interface. We expect you will find IPDaemon as easy to use as IPPort.
By default, each instance of IPDaemon can handle up to 1,000 simultaneous
incoming connections (this number may be increased up to 100,000 or decreased to
a lower value by using the MaxConnections
configuration setting).
The connections are identified by a ConnectionId , an id generated by the component to identify each connection. This id is unique to each connection. IPDaemon's events also have ConnectionId as a parameter to identify the connection they relate to.
Our main goal in designing IPDaemon was to make it easy to use without
sacrificing performance. The bean has a minimum of properties, and
six events: ConnectionRequest
, Connected
, DataIn
, Disconnected
, ReadyToSend
, and Error
.
IPDaemon can start to listen on a port by setting the Listening
property to True. When a remote host asks for a connection, the ConnectionRequest
event is
fired. At that point, the connection can either be accepted or rejected. If
the connection is accepted, a ConnectionId is assigned, and communication can
start. From this point on, the operation is very similar to IPPort. Data is
sent by assigning the data string to the DataToSend
property. The address
and port of the incoming connection can be found by querying the RemoteHost
and RemotePort
properties.
Constructor Summary | |
---|---|
Ipdaemon()
Creates an instance of Ipdaemon Bean. |
|
Ipdaemon(java.lang.String runtimeLicense)
Creates an instance of Ipdaemon Bean with specified run-time license. |
Method Summary | |
---|---|
void |
addIpdaemonEventListener(IpdaemonEventListener l)
|
java.lang.String |
config(java.lang.String configurationString)
Sets or retrieves a configuration setting. |
void |
disconnect(java.lang.String connectionId)
Disconnect the specified client. |
void |
doEvents()
Processes events from the internal message queue. |
int |
getConnectionBacklog()
The maximum number of pending connections maintained by the TCP/IP subsystem. |
ConnectionMap |
getConnections()
A collection of currently connected clients. |
byte[] |
getDefaultEOL()
A default EOL value to be used by incoming connections. |
int |
getDefaultMaxLineLength()
The default maximum line length value for inbound connections. |
int |
getDefaultTimeout()
An initial timeout value to be used by incoming connections. |
java.lang.String |
getLocalHost()
The name of the local host or user-assigned IP interface through which connections are initiated or accepted. |
int |
getLocalPort()
The TCP port in the local host where the bean listens. |
void |
interrupt(java.lang.String connectionId)
Interrupts a synchronous send to the remote host. |
boolean |
isDefaultSingleLineMode()
Tells the bean whether or not to treat new connections as line-oriented. |
boolean |
isKeepAlive()
When True, KEEPALIVE packets are enabled (for long connections). |
boolean |
isLinger()
When set to True, connections are terminated gracefully. |
boolean |
isListening()
If True, the bean accepts incoming connections on LocalPort. |
void |
removeIpdaemonEventListener(IpdaemonEventListener l)
|
void |
send(java.lang.String connectionId,
byte[] text)
Sends data to the remote host. |
void |
sendFile(java.lang.String connectionId,
java.lang.String fileName)
Send file to the remote host. |
void |
sendLine(java.lang.String connectionId,
java.lang.String text)
Sends a string followed by a newline. |
void |
setConnectionBacklog(int connectionBacklog)
The maximum number of pending connections maintained by the TCP/IP subsystem. |
void |
setDefaultEOL(byte[] defaultEOL)
A default EOL value to be used by incoming connections. |
void |
setDefaultMaxLineLength(int defaultMaxLineLength)
The default maximum line length value for inbound connections. |
void |
setDefaultSingleLineMode(boolean defaultSingleLineMode)
Tells the bean whether or not to treat new connections as line-oriented. |
void |
setDefaultTimeout(int defaultTimeout)
An initial timeout value to be used by incoming connections. |
void |
setKeepAlive(boolean keepAlive)
When True, KEEPALIVE packets are enabled (for long connections). |
void |
setLinger(boolean linger)
When set to True, connections are terminated gracefully. |
void |
setListening(boolean listening)
If True, the bean accepts incoming connections on LocalPort. |
void |
setLocalHost(java.lang.String localHost)
The name of the local host or user-assigned IP interface through which connections are initiated or accepted. |
void |
setLocalPort(int localPort)
The TCP port in the local host where the bean listens. |
void |
shutdown()
Shuts down the server. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Ipdaemon()
public Ipdaemon(java.lang.String runtimeLicense)
Method Detail |
---|
public int getConnectionBacklog()
This property contains the maximum number of pending connections maintained by the TCP/IP subsystem. This value reflects the SOMAXCON option for the main listening socket. The default value for most systems is 5. You may set this property to a larger value if the server is expected to receive a large number of connections, and queuing them is desirable.
public void setConnectionBacklog(int connectionBacklog) throws IPWorksException
This property contains the maximum number of pending connections maintained by the TCP/IP subsystem. This value reflects the SOMAXCON option for the main listening socket. The default value for most systems is 5. You may set this property to a larger value if the server is expected to receive a large number of connections, and queuing them is desirable.
IPWorksException
public ConnectionMap getConnections()
This property contains a collection of currently connected clients.
All of the connections may be managed using this property. Each connection is described by the different fields of the connection
type.
This collection is a hashtable type of collection, in which the Connection ID string is used as the key to the desired connection. You may acquire the key for a given connection through the Connected
event.
Example (Broadcasting Data)
Iterator keys = ipdaemon1.getConnections().keySet().iterator();
while (keys.hasNext()) {
Connection c = (Connection) ipdaemon1.getConnections().get(keys.next());
c.setDataToSend("Broadcast Data");
}
public byte[] getDefaultEOL()
This property contains a default End Of Line (EOL) value to be used by incoming connections. Once the bean accepts and establishes an inbound connection, it will set that connection's EOL to the value in this property. By default, this value is empty (""), meaning that data will be fired as it is received.
public void setDefaultEOL(byte[] defaultEOL) throws IPWorksException
This property contains a default End Of Line (EOL) value to be used by incoming connections. Once the bean accepts and establishes an inbound connection, it will set that connection's EOL to the value in this property. By default, this value is empty (""), meaning that data will be fired as it is received.
IPWorksException
public int getDefaultMaxLineLength()
This property controls the default size of an internal buffer which holds received data while waiting for an end-of-line (EOL) string.
The minimum value for this property is 256 bytes. The default value is 2048 bytes. The maximum value is 65536 bytes.
public void setDefaultMaxLineLength(int defaultMaxLineLength) throws IPWorksException
This property controls the default size of an internal buffer which holds received data while waiting for an end-of-line (EOL) string.
The minimum value for this property is 256 bytes. The default value is 2048 bytes. The maximum value is 65536 bytes.
IPWorksException
public boolean isDefaultSingleLineMode()
This property instructs the component whether or not to treat newly established connections as line-oriented protocols. If this value is True, newly accepted connections will read the incoming data stream as lines separated by CRLF, CR, or LF, and will ignore the end of lines (EOLs).
public void setDefaultSingleLineMode(boolean defaultSingleLineMode) throws IPWorksException
This property instructs the component whether or not to treat newly established connections as line-oriented protocols. If this value is True, newly accepted connections will read the incoming data stream as lines separated by CRLF, CR, or LF, and will ignore the end of lines (EOLs).
IPWorksException
public int getDefaultTimeout()
This property is used by the bean to set the operational timeout value of all inbound connections once they are established. By default, the timeout is 0, meaning that all inbound connections will behave asynchronously.
public void setDefaultTimeout(int defaultTimeout) throws IPWorksException
This property is used by the bean to set the operational timeout value of all inbound connections once they are established. By default, the timeout is 0, meaning that all inbound connections will behave asynchronously.
IPWorksException
public boolean isKeepAlive()
This property enables the SO_KEEPALIVE option on the incoming connections. This option prevents long connections from timing out in case of inactivity.
Please note that system TCP/IP stack implementations are not required to support SO_KEEPALIVE.
This property is shared among incoming connections. When the property is set, the corresponding value is set for incoming connections as they are accepted. Existing connections are not modified.
public void setKeepAlive(boolean keepAlive) throws IPWorksException
This property enables the SO_KEEPALIVE option on the incoming connections. This option prevents long connections from timing out in case of inactivity.
Please note that system TCP/IP stack implementations are not required to support SO_KEEPALIVE.
This property is shared among incoming connections. When the property is set, the corresponding value is set for incoming connections as they are accepted. Existing connections are not modified.
IPWorksException
public boolean isLinger()
This property controls how a connection is closed. The default is True. In this case the connection is closed only after all the data is sent. Setting it to False forces an abrupt (hard) disconnection. Any data that was in the sending queue may be lost.
The default behavior (which is also the default mode for stream sockets) might result in an indefinite delay in closing the connection. Although the bean returns control immediately, the system might indefinitely hold system resources until all pending data is sent (even after your application closes). This means that valuable system resources might be wasted.
Setting this property to False forces an immediate disconnection. If you know that the other side has received all the data you have sent (by a client acknowledgment, for example), setting this property to False might be the appropriate course of action.
This property is shared among incoming connections. When the property is set, the corresponding value is set for incoming connections as they are accepted. Existing connections are not modified.
public void setLinger(boolean linger) throws IPWorksException
This property controls how a connection is closed. The default is True. In this case the connection is closed only after all the data is sent. Setting it to False forces an abrupt (hard) disconnection. Any data that was in the sending queue may be lost.
The default behavior (which is also the default mode for stream sockets) might result in an indefinite delay in closing the connection. Although the bean returns control immediately, the system might indefinitely hold system resources until all pending data is sent (even after your application closes). This means that valuable system resources might be wasted.
Setting this property to False forces an immediate disconnection. If you know that the other side has received all the data you have sent (by a client acknowledgment, for example), setting this property to False might be the appropriate course of action.
This property is shared among incoming connections. When the property is set, the corresponding value is set for incoming connections as they are accepted. Existing connections are not modified.
IPWorksException
public boolean isListening()
Use this property to make the bean 'listen' (accept connections) on the port specified by the LocalPort
property. Setting this property to False will make the bean stop listening. (Please note that this does not close any existing connections).
public void setListening(boolean listening) throws IPWorksException
Use this property to make the bean 'listen' (accept connections) on the port specified by the LocalPort
property. Setting this property to False will make the bean stop listening. (Please note that this does not close any existing connections).
IPWorksException
public java.lang.String getLocalHost()
The LocalHost
property contains the name of the local host
as obtained by the gethostname() system call, or if the
user has assigned an IP address, the value of that address.
In multi-homed hosts (machines with more than one IP interface) setting LocalHost to the value of an interface will make the bean initiate connections (or accept in the case of server beans) only through that interface.
If the bean is connected, the LocalHost
property shows
the IP address of the interface through which the connection
is made in internet dotted format (aaa.bbb.ccc.ddd). In most
cases, this is the address of the local host, except for multi-homed
hosts (machines with more than one IP interface).
NOTE: LocalHost
is not persistent. You must always set it in
code, and never in the property window.
public void setLocalHost(java.lang.String localHost) throws IPWorksException
The LocalHost
property contains the name of the local host
as obtained by the gethostname() system call, or if the
user has assigned an IP address, the value of that address.
In multi-homed hosts (machines with more than one IP interface) setting LocalHost to the value of an interface will make the bean initiate connections (or accept in the case of server beans) only through that interface.
If the bean is connected, the LocalHost
property shows
the IP address of the interface through which the connection
is made in internet dotted format (aaa.bbb.ccc.ddd). In most
cases, this is the address of the local host, except for multi-homed
hosts (machines with more than one IP interface).
NOTE: LocalHost
is not persistent. You must always set it in
code, and never in the property window.
IPWorksException
public int getLocalPort()
This property must be set before the bean can start listening. If its value is 0, then the TCP/IP subsystem picks a port number at random.
The port number can be found by checking the value of this property after the bean is listening (ie. after successfully assigning True
to the Listening
property).
The service port is not shared among servers so two beans cannot be listening on the same port at the same time.
public void setLocalPort(int localPort) throws IPWorksException
This property must be set before the bean can start listening. If its value is 0, then the TCP/IP subsystem picks a port number at random.
The port number can be found by checking the value of this property after the bean is listening (ie. after successfully assigning True
to the Listening
property).
The service port is not shared among servers so two beans cannot be listening on the same port at the same time.
IPWorksException
public java.lang.String config(java.lang.String configurationString) throws IPWorksException
Config
is a generic method available in every bean.
It is used to set and retrieve configuration settings
for the
bean.
Configuration settings are similar in functionality to properties,
but they are rarely used. In order to avoid "polluting" the property
namespace of the bean, access to these internal properties is provided through the Config
method.
To set a configuration setting named PROPERTY , you must call Config("PROPERTY=VALUE") , where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).
To read (query) the value of a configuration setting, you must call Config("PROPERTY") . The value will be returned as a string.
The bean accepts one or more of the following configuration settings .
Configuration settings are similar in functionality to properties,
but they are rarely used. In order to avoid "polluting" the property
namespace of the bean, access to these internal properties is provided through the Config
method.
InBufferSize is shared among incoming connections. When the property is set, the corresponding value is set for incoming connections as they are accepted. Existing connections are not modified.
Listening
is set
to True, and once set, it can no longer be changed for the current instance of the bean.
The maximum value for this setting is 100,000 connections.OutBufferSize is shared among incoming connections. When the property is set, the corresponding value is set for incoming connections as they are accepted. Existing connections are not modified.
IPWorksException
public void disconnect(java.lang.String connectionId) throws IPWorksException
Calling this method will disconnect the client specified by the ConnectionId parameter.
IPWorksException
public void doEvents() throws IPWorksException
When DoEvents
is called, the bean processes any
available events. If no events are available, it waits for a
preset period of time, and then returns.
IPWorksException
public void interrupt(java.lang.String connectionId) throws IPWorksException
This property is called using the Connection ID if you wish to interrupt a connection and stop a file from uploading without disconnecting the client connected to the bean. If you use SendFile
to upload a file, the bean will run synchronously on that Connection ID until it is completed.
IPWorksException
public void send(java.lang.String connectionId, byte[] text) throws IPWorksException
This method sends data to the remote host. Calling this method is equivalent to setting the DataToSend
property to Text .
IPWorksException
public void sendFile(java.lang.String connectionId, java.lang.String fileName) throws IPWorksException
This method sends the file to the client specified by the ConnectionId .
IPWorksException
public void sendLine(java.lang.String connectionId, java.lang.String text) throws IPWorksException
This method is used to send data with line-oriented protocols. The line is followed by CRLF ("\\r\\n") .
Please refer to the GetLine
method and SingleLineMode
property for more information.
IPWorksException
public void shutdown() throws IPWorksException
This method shuts down the server. Calling this method is equivalent to setting Listening
to False,
and then breaking every client connection by calling Disconnect
.
IPWorksException
public void addIpdaemonEventListener(IpdaemonEventListener l) throws java.util.TooManyListenersException
java.util.TooManyListenersException
public void removeIpdaemonEventListener(IpdaemonEventListener l)
|
IP*Works! V9 | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |