18.2. Simple connectivity techniques

18.2.1. The Socket API

There is no reason in theory why communication with our quote server should not be implemented directly by an EJB using Java sockets. This technique is specifically allowed for in the EJB Specification [EJB2.0 24.2.1]. If the designer encapsulates the communication inside a dedicated class or EJB, the code will not be particularly objectionable.

In practice, the EJB can execute code something like this:

Socket s = new Socket (’someserver’, somePort); 
//... read and write socket 
s.close(); 

The container has to support this, because method calls between EJBs can be network calls.

The problems with this strategy should be fairly obvious.

  • The developer has to do all the work: The Socket ...

Get Applied Enterprise JavaBeans™ Technology now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.