public class NetAdapterHost extends java.lang.Object implements java.lang.Runnable, NetAdapterConstants
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)
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)
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
createMulticastListener()
.
For information on creating the client component, see the JavaDocs
for the NetAdapter
.
NetAdapter
NetAdapterConstants.Connection
BUFFERED_OUTPUT, CMD_BEGINEXCLUSIVE, CMD_CANBREAK, CMD_CANDELIVERPOWER, CMD_CANDELIVERSMARTPOWER, CMD_CANFLEX, CMD_CANHYPERDRIVE, CMD_CANOVERDRIVE, CMD_CANPROGRAM, CMD_CLOSECONNECTION, CMD_DATABLOCK, CMD_ENDEXCLUSIVE, CMD_EXCLUDEFAMILY, CMD_FINDFIRSTDEVICE, CMD_FINDNEXTDEVICE, CMD_GETADDRESS, CMD_GETBIT, CMD_GETBLOCK, CMD_GETBYTE, CMD_GETSPEED, CMD_PINGCONNECTION, CMD_PUTBIT, CMD_PUTBYTE, CMD_RESET, CMD_SETNORESETSEARCH, CMD_SETPOWERDURATION, CMD_SETPOWERNORMAL, CMD_SETPROGRAMPULSEDURATION, CMD_SETSEARCHALLDEVICES, CMD_SETSEARCHONLYALARMINGDEVICES, CMD_SETSPEED, CMD_STARTBREAK, CMD_STARTPOWERDELIVERY, CMD_STARTPROGRAMPULSE, CMD_TARGETALLFAMILIES, CMD_TARGETFAMILY, DEBUG, DEFAULT_MULTICAST_GROUP, DEFAULT_MULTICAST_PORT, DEFAULT_PORT, DEFAULT_SECRET, EMPTY_CONNECTION, RET_FAILURE, RET_SUCCESS, versionUID
Constructor and Description |
---|
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,
java.net.ServerSocket serverSock)
Creates an instance of a NetAdapterHost which wraps the provided
adapter.
|
NetAdapterHost(DSPortAdapter adapter,
java.net.ServerSocket serverSock,
boolean multiThread)
Creates an (optionally multi-threaded) instance of a NetAdapterHost which
wraps the provided adapter.
|
Modifier and Type | Method and Description |
---|---|
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,
java.lang.String group)
Creates a Multicast Listener to allow NetAdapter clients to discover
this NetAdapterHost automatically.
|
void |
handleConnection(java.net.Socket sock)
Handles a socket connection.
|
static void |
main(java.lang.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(java.lang.String secret)
Sets the secret used for authenticating incoming client connections.
|
void |
stopHost()
Stops all threads and kills the server socket.
|
public NetAdapterHost(DSPortAdapter adapter) throws java.io.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.java.io.IOException
- if a network error occurs or the listen socket
cannot be created on the specified port.public NetAdapterHost(DSPortAdapter adapter, int listenPort) throws java.io.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 connectionsjava.io.IOException
- if a network error occurs or the listen socket
cannot be created on the specified port.public NetAdapterHost(DSPortAdapter adapter, boolean multiThread) throws java.io.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.java.io.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 java.io.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.java.io.IOException
- if a network error occurs or the listen socket
cannot be created on the specified port.public NetAdapterHost(DSPortAdapter adapter, java.net.ServerSocket serverSock) throws java.io.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 connectionsjava.io.IOException
- if a network error occurs or the listen socket
cannot be created on the specified port.public NetAdapterHost(DSPortAdapter adapter, java.net.ServerSocket serverSock, boolean multiThread) throws java.io.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.java.io.IOException
- if a network error occurs or the listen socket
cannot be created on the specified port.public void setSecret(java.lang.String secret)
secret
- The shared secret information used for authenticating
incoming client connections.public void createMulticastListener() throws java.io.IOException, java.net.UnknownHostException
java.io.IOException
java.net.UnknownHostException
public void createMulticastListener(int port) throws java.io.IOException, java.net.UnknownHostException
port
- The port the Multicast socket will receive packets onjava.io.IOException
java.net.UnknownHostException
public void createMulticastListener(int port, java.lang.String group) throws java.io.IOException, java.net.UnknownHostException
port
- The port the Multicast socket will receive packets ongroup
- The group the Multicast socket will joinjava.io.IOException
java.net.UnknownHostException
public void run()
run
in interface java.lang.Runnable
public void handleConnection(java.net.Socket sock) throws java.io.IOException
java.io.IOException
public void stopHost()
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
Copyright © 1999-2012 Maxim Integrated Products. All Rights Reserved.