1-Wire API for .NET Version 4.00
Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes

NetAdapterHost Class Reference

Inherits com::dalsemi::onewire::adapter::NetAdapterConstants.

List of all members.

Public Member Functions

 NetAdapterHost (DSPortAdapter adapter) throws IOException
 NetAdapterHost (DSPortAdapter adapter, int listenPort) throws IOException
 NetAdapterHost (DSPortAdapter adapter, boolean multiThread) throws IOException
 NetAdapterHost (DSPortAdapter adapter, int listenPort, boolean multiThread) throws IOException
 NetAdapterHost (DSPortAdapter adapter, ServerSocket serverSock) throws IOException
 NetAdapterHost (DSPortAdapter adapter, ServerSocket serverSock, boolean multiThread) throws IOException
void setSecret (String secret)
 Sets the secret used for authenticating incoming client connections.
void createMulticastListener () throws IOException,UnknownHostException
 Creates a Multicast Listener to allow NetAdapter clients to discover this NetAdapterHost automatically.
void createMulticastListener (int port) throws IOException,UnknownHostException
 Creates a Multicast Listener to allow NetAdapter clients to discover this NetAdapterHost automatically.
void createMulticastListener (int port, String group) throws IOException,UnknownHostException
 Creates a Multicast Listener to allow NetAdapter clients to discover this NetAdapterHost automatically.
void run ()
 Run method for threaded NetAdapterHost.
void handleConnection (Socket sock) throws IOException
 Handles a socket connection.
void stopHost ()
 Stops all threads and kills the server socket.

Static Public Member Functions

static void main (String[] args) throws Exception
 A Default Main Method, for launching NetAdapterHost getting the default adapter with the OneWireAccessProvider and listening on the default port specified by DEFAULT_PORT.

Protected Attributes

DSPortAdapter adapter = null
 The adapter this NetAdapter will proxy too.
ServerSocket serverSocket = null
 The server socket for listening for connections.
byte[] netAdapterSecret = null
 secret for authentication with the server
volatile boolean hostStopped = false
 boolean flags for stopping the host
boolean singleThreaded = true
 boolean flag to indicate whether or not the host is single or multi-threaded
Hashtable hashHandlers = null
 Map of all Service threads created, only for multi-threaded.
MulticastListener multicastListener = null
 Optional, listens for datagram packets from potential clients.
int timeoutInSeconds = 30
 timeout for socket receive, in seconds

Static Protected Attributes

static final Random rand = new Random()
 random number generator, used to issue challenges to client

Detailed Description

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 also:
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:

Optionally, the secret can be set by calling the setSecret(String) {

See also:
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 also:
createMulticastListener()}.

For information on creating the client component, see the JavaDocs for the NetAdapter.

See also:
NetAdapter
Author:
SH
Version:
1.00, 9 Jan 2002

Constructor & Destructor Documentation

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.

Parameters:
adapterDSPortAdapter that this NetAdapterHost will proxy commands to.
Exceptions:
IOExceptionif a network error occurs or the listen socket cannot be created on the specified port.
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.

Parameters:
adapterDSPortAdapter that this NetAdapterHost will proxy commands to.
listenPortthe TCP/IP port to listen on for incoming connections
Exceptions:
IOExceptionif a network error occurs or the listen socket cannot be created on the specified port.
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.

Parameters:
adapterDSPortAdapter that this NetAdapterHost will proxy commands to.
multiThreadif true, multiple TCP/IP connections are allowed to interact simulataneously with this adapter.
Exceptions:
IOExceptionif a network error occurs or the listen socket cannot be created on the specified port.
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.

Parameters:
adapterDSPortAdapter that this NetAdapterHost will proxy commands to.
listenPortthe TCP/IP port to listen on for incoming connections
multiThreadif true, multiple TCP/IP connections are allowed to interact simulataneously with this adapter.
Exceptions:
IOExceptionif a network error occurs or the listen socket cannot be created on the specified port.
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.

Parameters:
adapterDSPortAdapter that this NetAdapterHost will proxy commands to.
serverSockthe ServerSocket for incoming connections
Exceptions:
IOExceptionif a network error occurs or the listen socket cannot be created on the specified port.
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.

Parameters:
adapterDSPortAdapter that this NetAdapterHost will proxy commands to.
serverSockthe ServerSocket for incoming connections
multiThreadif true, multiple TCP/IP connections are allowed to interact simulataneously with this adapter.
Exceptions:
IOExceptionif a network error occurs or the listen socket cannot be created on the specified port.

Member Function Documentation

void createMulticastListener ( ) throws IOException,UnknownHostException

Creates a Multicast Listener to allow NetAdapter clients to discover this NetAdapterHost automatically.

Uses defaults for Multicast group and port.

void createMulticastListener ( int  port,
String  group 
) throws IOException,UnknownHostException

Creates a Multicast Listener to allow NetAdapter clients to discover this NetAdapterHost automatically.

Parameters:
portThe port the Multicast socket will receive packets on
groupThe group the Multicast socket will join
void createMulticastListener ( int  port) throws IOException,UnknownHostException

Creates a Multicast Listener to allow NetAdapter clients to discover this NetAdapterHost automatically.

Uses default for Multicast group.

Parameters:
portThe port the Multicast socket will receive packets on
void handleConnection ( Socket  sock) throws IOException

Handles a socket connection.

If single-threaded, the connection is serviced in the current thread. If multi-threaded, a new thread is created for servicing this connection.

void run ( )

Run method for threaded NetAdapterHost.

Maintains server socket which waits for incoming connections. Whenever a connection is received launches it services the socket or (optionally) launches a new thread for servicing the socket.

void setSecret ( String  secret)

Sets the secret used for authenticating incoming client connections.

Parameters:
secretThe shared secret information used for authenticating incoming client connections.

The documentation for this class was generated from the following file: