|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.dalsemi.onewire.adapter.NetAdapterHost
NetAdapterHost is the host (or server) component for a network-based DSPortAdapter. It actually wraps the hardware DSPortAdapter and handles connections from outside sources (NetAdapter) who want to access it.
NetAdapterHost is designed to be run in a thread, waiting for incoming
connections. You can run this in the same thread as your main program or
you can establish the connections yourself (presumably using some higher
level of security) and then call the handleConnection(Socket)
{@see #handleConnection(Socket)}.
Once a NetAdapter is connected with the host, a version check is performed followed by a simple authentication step. The authentication is dependent upon a secret shared between the NetAdapter and the host. Both will use a default value, that each will agree with if you don't provide a secret of your own. To set the secret, add the following line to your onewire.properties file:
setSecret(String)
{@see #setSecret(String)}
The NetAdapter and NetAdapterHost support multicast broadcasts for
automatic discovery of compatible servers on your LAN. To start the
multicast listener for this NetAdapterHost, call the
createMulticastListener()
method
{@see #createMulticastListener()}.
For information on creating the client component, see the JavaDocs for the {@link com.dalsemi.onewire.adapter.NetAdapter NetAdapter}.
NetAdapter
Constructor Summary | |
NetAdapterHost(DSPortAdapter adapter)
Creates an instance of a NetAdapterHost which wraps the provided adapter. |
|
NetAdapterHost(DSPortAdapter adapter,
boolean multiThread)
Creates an (optionally multithreaded) instance of a NetAdapterHost which wraps the provided adapter. |
|
NetAdapterHost(DSPortAdapter adapter,
int listenPort)
Creates a single-threaded instance of a NetAdapterHost which wraps the provided adapter. |
|
NetAdapterHost(DSPortAdapter adapter,
int listenPort,
boolean multiThread)
Creates an (optionally multi-threaded) instance of a NetAdapterHost which wraps the provided adapter. |
|
NetAdapterHost(DSPortAdapter adapter,
ServerSocket serverSock)
Creates an instance of a NetAdapterHost which wraps the provided adapter. |
|
NetAdapterHost(DSPortAdapter adapter,
ServerSocket serverSock,
boolean multiThread)
Creates an (optionally multi-threaded) instance of a NetAdapterHost which wraps the provided adapter. |
Method Summary | |
void |
createMulticastListener()
Creates a Multicast Listener to allow NetAdapter clients to discover this NetAdapterHost automatically. |
void |
createMulticastListener(int port)
Creates a Multicast Listener to allow NetAdapter clients to discover this NetAdapterHost automatically. |
void |
createMulticastListener(int port,
String group)
Creates a Multicast Listener to allow NetAdapter clients to discover this NetAdapterHost automatically. |
void |
handleConnection(Socket sock)
Handles a socket connection. |
static void |
main(String[] args)
A Default Main Method, for launching NetAdapterHost getting the default adapter with the OneWireAccessProvider and listening on the default port specified by DEFAULT_PORT. |
void |
run()
Run method for threaded NetAdapterHost. |
void |
setSecret(String secret)
Sets the secret used for authenticating incoming client connections. |
void |
stopHost()
Stops all threads and kills the server socket. |
Constructor Detail |
public NetAdapterHost(DSPortAdapter adapter) throws IOException
Creates an instance of a NetAdapterHost which wraps the provided adapter. The host listens on the default port as specified by NetAdapterConstants.
Note that the secret used for authentication is the value specified
in the onewire.properties file as "NetAdapter.secret=mySecret".
To set the secret to another value, use the
setSecret(String)
method.
adapter
- DSPortAdapter that this NetAdapterHost will proxy
commands to.IOException
- if a network error occurs or the listen socket
cannot be created on the specified port.public NetAdapterHost(DSPortAdapter adapter, int listenPort) throws IOException
Creates a single-threaded instance of a NetAdapterHost which wraps the provided adapter. The host listens on the specified port.
Note that the secret used for authentication is the value specified
in the onewire.properties file as "NetAdapter.secret=mySecret".
To set the secret to another value, use the
setSecret(String)
method.
adapter
- DSPortAdapter that this NetAdapterHost will proxy
commands to.listenPort
- the TCP/IP port to listen on for incoming connectionsIOException
- if a network error occurs or the listen socket
cannot be created on the specified port.public NetAdapterHost(DSPortAdapter adapter, boolean multiThread) throws IOException
Creates an (optionally multithreaded) instance of a NetAdapterHost which wraps the provided adapter. The listen port is set to the default port as defined in NetAdapterConstants.
Note that the secret used for authentication is the value specified
in the onewire.properties file as "NetAdapter.secret=mySecret".
To set the secret to another value, use the
setSecret(String)
method.
adapter
- DSPortAdapter that this NetAdapterHost will proxy
commands to.multiThread
- if true, multiple TCP/IP connections are allowed
to interact simulataneously with this adapter.IOException
- if a network error occurs or the listen socket
cannot be created on the specified port.public NetAdapterHost(DSPortAdapter adapter, int listenPort, boolean multiThread) throws IOException
Creates an (optionally multi-threaded) instance of a NetAdapterHost which wraps the provided adapter. The host listens on the specified port.
Note that the secret used for authentication is the value specified
in the onewire.properties file as "NetAdapter.secret=mySecret".
To set the secret to another value, use the
setSecret(String)
method.
adapter
- DSPortAdapter that this NetAdapterHost will proxy
commands to.listenPort
- the TCP/IP port to listen on for incoming connectionsmultiThread
- if true, multiple TCP/IP connections are allowed
to interact simulataneously with this adapter.IOException
- if a network error occurs or the listen socket
cannot be created on the specified port.public NetAdapterHost(DSPortAdapter adapter, ServerSocket serverSock) throws IOException
Creates an instance of a NetAdapterHost which wraps the provided adapter. The host listens on the default port as specified by NetAdapterConstants.
Note that the secret used for authentication is the value specified
in the onewire.properties file as "NetAdapter.secret=mySecret".
To set the secret to another value, use the
setSecret(String)
method.
adapter
- DSPortAdapter that this NetAdapterHost will proxy
commands to.serverSock
- the ServerSocket for incoming connectionsIOException
- if a network error occurs or the listen socket
cannot be created on the specified port.public NetAdapterHost(DSPortAdapter adapter, ServerSocket serverSock, boolean multiThread) throws IOException
Creates an (optionally multi-threaded) instance of a NetAdapterHost which wraps the provided adapter. The host listens on the specified port.
Note that the secret used for authentication is the value specified
in the onewire.properties file as "NetAdapter.secret=mySecret".
To set the secret to another value, use the
setSecret(String)
method.
adapter
- DSPortAdapter that this NetAdapterHost will proxy
commands to.serverSock
- the ServerSocket for incoming connectionsmultiThread
- if true, multiple TCP/IP connections are allowed
to interact simulataneously with this adapter.IOException
- if a network error occurs or the listen socket
cannot be created on the specified port.Method Detail |
public void setSecret(String secret)
secret
- The shared secret information used for authenticating
incoming client connections.public void createMulticastListener() throws IOException, UnknownHostException
public void createMulticastListener(int port) throws IOException, UnknownHostException
port
- The port the Multicast socket will receive packets onpublic void createMulticastListener(int port, String group) throws IOException, UnknownHostException
port
- The port the Multicast socket will receive packets ongroup
- The group the Multicast socket will joinpublic void run()
run
in interface Runnable
public void handleConnection(Socket sock) throws IOException
public void stopHost()
public static void main(String[] args) throws Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |