TalkToHost is a LANDP client that accesses SNA communication functions, using an LU0 connection. These include opening a connection with a host, sending and receiving messages and closing the connection.
It requests a SNA session to communicate with, an application name to send messages to, and a message to send.
The client also uses some Supervisor wrapper methods, including the standard functions to connect and disconnect from LANDP, and a method to wait for a response from the SNA server.
To run TalkToHost, a SNA server is required within a LANDP workgroup. This should be configured so that it can communicate with a host application using an LU-LU session. For more information on installing and customising a workgroup, see the LANDP Installation and Customisation manual - Appendix D. A useful example of how to set up a small workgroup with an SNA server is provided in Appendix A.
Having registered with the Java manager, the RemoteRequest object which is returned is used as a parameter to create new instances of the Supervisor and SNA Server classes.
The Supervisor server is needed for the connect() function to connect to LANDP services. The application then reads in the users input for a SNA server to connect to. It then attempts to connect to this server using the openSessionSNA() method, which if successful, creates a new HostSession object.
The user is prompted for an application to connect to, and to make this connection, the HostSession is retrieved using getSessionSNA(), before calling the openLU() method on this HostSession.
The user is then prompted for a message to send to the host. A new instance of HostMessage is created, constructed with the message as a parameter. This message is then sent to the host using the sendHostMessage() method of the HostSession class, taking a HostMessage object as a parameter.
The application then uses a Supervisor class method waitForEvent() to wait for a response from the host. Once a response has been received, control returns to the application. The message status is checked using the getMessageStatus() function, which returns true if a message is pending. This message is read using the readHostMessage() method of the HostSession class, which returns a HostMessage object. To read the physical message, the getText() method of HostMessage is called which returns the message in String format.
To close the connection to the application, the closeLU() method of HostSession is called.
To close the SNA session, the closeSessionSNA() of the SNAserver class is called.
Finally the disconnect() method of the Supervisor class is called to close the connection with LANDP.
The source code for the SNA application is provided with this tutorial.