The simple length indicated protocol (SLIP) provides an implementation of a basic protocol in which messages are prefixed with a header containing a payload length indicator. The SLIP message header may also contain a configurable number of bytes as padding. In addition, a maximum payload may be configured such that messages who's length is in violation of the payload limitation cause the channel to be closed (to prevent malicious use).

The payload length indicator is encoded in the header as one of the following:

The SLIP protocol implementation leverages an underlying transport protocol to send/receive SLIP messages. This transport protocol used by SLIP may be configured as any protocol that supports the 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.

SLIP How-To

  1. Initializing a SLIP Access Point

    In order to use the SLIP protocol, clients and servers access SLIP channels via the 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");
    	

  2. Creating a SLIP Server

    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();
    	}
    	

  3. Creating a SLIP Client

    The following example describes how to create a SLIP client.
    	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) {
    		...
    	}
    	
  4. Reading and Writing SLIP Messages

    The following example code demonstrates how to write using a SLIP channel.
    	byte message[] = ...
    	try {
    		slipChannel.write(message);
    	} catch(IOException ioe) {
    		...
    		
    		// if an error occurs writing, ensure the channel is closed
    		slipChannel.close();
    	}
    	
  5. Managing SLIP Channels