Implements the lowest lever layer which allows to open a socket in a certain IP and port. At the same time, the service runs in the execution time in a Axional Studio already running. Create and start the service.

1 socket.addServiceClass

    <Service Class /> +

The following example shows how a socket service is created and how it runs. To test it, a socket client which sends a message to the service is declared. The service print on screen the answer and then, the service stops.

<xsql-script name='addServiceClass'>
  <socket.addServiceClass name='echo' host='' port='5555' backlog='5' so-rcvbuf='128' log-time='5'>
      public class echo extends NioService
            private int READ_MESSAGE_WAIT_TIME  = 10;
            private int WRITE_MESSAGE_WAIT_TIME = 10;
        	public void handleAcceptConnection(AsynchronousSocketChannel asyncSocketChannel)
        		throws Exception
        		ByteBuffer messageByteBuffer = ByteBuffer.allocate(getMessageReadSize());
        		// read a message from the client, timeout after 10 seconds
        		Future<Integer> futureReadResult =;
        		futureReadResult.get(READ_MESSAGE_WAIT_TIME, TimeUnit.SECONDS);
        		String clientMessage = new String(messageByteBuffer.array()).trim();
        		String responseString = "echo:" + clientMessage + "\n";
        		messageByteBuffer = ByteBuffer.wrap((responseString.getBytes()));
        		Future<Integer> futureWriteResult = asyncSocketChannel.write(messageByteBuffer);
        		futureWriteResult.get(WRITE_MESSAGE_WAIT_TIME, TimeUnit.SECONDS);
        		if (messageByteBuffer.hasRemaining()) {
        		} else {
] ]>
  <!-- TEST CLIENT -->
  <!-- declare a socket to connecto to echo server -->
  <set name='m_socket'>
   <socket host='' port='5555' timeout='2' />
  <!-- send a message to echo -->
     <m_socket />
     <string>Hello from client</string>
  <!-- read response from echo -->
     <m_socket />
  <!-- close the client socket -->
  <!-- stop socket server -->
  <socket.stopServiceClass name='echo' />