The payload length indicator is encoded in the header as one of the following:
com.newstep.solid.netio.StreamChannel construct.
NOTE: Unsigned integer lengths are not supported as they represent
positive values which may only be represented in Java through a long
primitive type. The long primitive is not accepted by the
java.nio.ByteBuffer manipulations and generally represents sizes
that are not practical for protocol manipulation.
com.newstep.solid.netio.ChannelAccessPoint construct.
As such, the com.newstep.solid.netio.slip.SlipAccesPoint must
be initialized with a valid
com.newstep.solid.netio.slip.SlipAccessPointConfiguration. In
creating and assigning the SLIP configuration, user's must assign a valid
transport protocol which supports the
com.newstep.solid.netio.StreamChannel interface.
The following example describes the creation of a SlipAccessPoint based on
the com.newstep.solid.netio.tcp protocol package.
// create the tcp access point config
ChannelAccessPointConfig tcpConfig = new ChannelAccessPointConfig();
tcpConfig.setFactoryClassName(TcpStreamAccessPointFactory.class.getName());
// create the slip access point config
SlipAccessPointConfig slipConfig = new SlipAccessPointConfig();
// assign the transport configuration to the slip access point config
slipConfig.setTransportAccessPointConfig(tcpConfig);
// create and initialize the slip access point named "SlipAP"
SlipAccessPoint slipAccessPoint = (SlipAccessPoint)AccessPointFactory.createAccessPoint(slipConfig, "SlipAP");
In order to create a SLIP Server
The following example describes how to create a SLIP server.
try {
// determine the local endpoint to use for listening
localEndpoint = new TcpChannelEndpoint("localhost", port);
// start the access point listening on the specified local end point
// for a limited number of connections and assign the new SlipChannel
// handler to deal with new SlipChannels when they are connected
slipAP.listen(localEndpoint, slipChannelHandler, numConnections);
} catch(UnknownHostException uhe) {
uhe.printStackTrace();
} catch(IOException ioe) {
ioe.printStackTrace();
}
ChannelEndpoint remoteEndPoint = null;
try {
remoteEndpoint = new TcpChannelEndpoint(ipAddress, port);
} catch(UnknownHostException uhe) {
...
}
try {
// create a handler for the client channel that will listen for messages
// and handle the channel lifecycle events
ExampleChannelHandler handler = new ExampleChannelHandler();
// open a SLIP channel to the remote end point and assign the handler as
// the channel's associated messsage listener
SlipChannel slipChannel = (SlipChannel)slipAP.openChannel(remoteEndpoint, (MessageListener)handler);
handler.setSlipChannel(slipChannel);
} catch(IOException ioe) {
...
}
byte message[] = ...
try {
slipChannel.write(message);
} catch(IOException ioe) {
...
// if an error occurs writing, ensure the channel is closed
slipChannel.close();
}