JXTA Pipes vs. Sockets

Some people are unsure about when it is appropriate to use JxtaSockets and when it appropriate to use Jxta Pipes (especially the JxtaBiDiPipe). These are a few of my reasons for deciding to choose sockets over pipes:

  • if your messages are (or could be) larger than 64K. Since 64K is the maximum message size for JXTA messages, you’re going to have to chunk them anyway. Why not let the socket layer take care of it for you? The socket code will ensure chunks are reassembled in the right order, and will take care of retransmissions if used in reliable mode.
  • If you need to make sure messages are received in the order they are sent. My understanding is that with pipes messages *usually* arrive ordered, but there’s no guarantee.
  • If you want to handle flow- and congestion-control automatically. With pipes, you’re on your own in figuring out how quickly to send messages, when to back off, and so on.
  • If you have existing code based on java.net.Socket, which you wish to convert or adapt to work in a JXTA network. Just don’t forget that you must explicitly flush() the output stream.

One exception is JxtaBiDiPipe. It has a reliable mode, so some of these reasons don’t apply. A JxtaBiDiPipe is reliable like a “reliable mode” socket, but you still have to do the message chunking yourself. You can use it in place of a socket if you don’t care about having a stream-based interface.

A further complication involves the use of secure sockets created using a JxtaUnicastSecure pipe and the TLS transport. Since reliability, flow- and congestion-control are provided by the TLS layer, you should turn the reliable mode off on the socket in this case to avoid inefficient duplication of effort.

In practical terms, it boils down to this for me: I generally use pipes for application-level protocol messages (usually unreliable JxtaBiDiPipes) and sockets for sending data (usually based on secure pipes, with the socket’s “stream”/reliable mode turned off.)

For a more detailed discussion of Pipe and Socket implementations and some common pitfalls, see “Demystifying Pipes, JxtaSockets, JxtaMulticastSocket, and JxtaBiDiPipes” by Mohamed Abdelaziz (hamada).

2 thoughts on “JXTA Pipes vs. Sockets”

  1. Thanks. Hope it helps. As for the stream mode, you have it right. The TLS transport takes care of retransmission etc. under the covers, so using a secure “stream” mode socket is redundant.

Leave a Reply

Your email address will not be published. Required fields are marked *