SAS as an Application

 

In this tutorial, we discuss how SAS can be used by a standalone application so that it can act as a proxy for SNMP communication. Manager applications can communicate with this application which in turn communicates with the actual devices and passes the results to the manager applications.

 

We need to use the SASAppletStub class in the snmp2 package. This class provides the implementation of the AppletStub methods to plug into applet to simulate applet behavior. This class is used to pass the "applet behavior" to the SnmpSession's open() method while using client applications (instead of applets) with SAS.

 

We also make use of the sasappclient applet provided in the "sasapps" directory. Refer the source code for sasappclient present in <examples/sasapps/sasappclient.java> for more information. This applet invokes the SASClient's userSyncSend() method to send data to the server to perform some operation. It receives the response data and prints it. It sends and receives the data continuously.

 

The example which we develop shows how applications can use the sasappclient file by plugging in their own applet stub. It instantiates the sasappclient object, sets the user-defined AppletStub stub into it.

 

We need to import the following packages.

 

import com.adventnet.management.transport.*;

import com.adventnet.snmp.snmp2.*;

import javax.swing.*;

import java.awt.event.*;

import java.net.*;

 

We define the required class and the static main function.

 

public class sastest extends JFrame

{

sastest()

{

super("SAS Application");

}

public static void main (String[] args)

{

 

Instantiate the sasappclient applet.

 

sastest testObj = new sastest();

final sasappclient obj = new sasappclient();

 

We instantiate the SASApplet stub class, plug it into the applet and set various parameters, such as host name, port, code base and document base.

 

//Create the Applet stub & plug it into the Applet

SASAppletStub sasStub = new SASAppletStub();

 

//set the transport provider

sasStub.setParameter("TRANSPORT_PROVIDER",

"com.adventnet.management.transport.TcpClientTransportImpl");

 

//localhost can be replaced by any host name

sasStub.setParameter("HOST","localhost");

 

//set the port parameter to the port in which SAServer is listening.

sasStub.setParameter("PORT","1575");

sasStub.setParameter("CODEBASE", "http://localhost:8282/");

sasStub.setParameter("DOCUMENTBASE", "http://localhost:8282/");

try {

URL codebase = new URL("http://localhost:8282/");

sasStub.setCodeBase(codebase);

sasStub.setDocumentBase(codebase);

}

catch (Exception e)

{

}

obj.setStub(sasStub);\

 

Now, we can start the applet.

 

// Start the Applet

obj.init();

obj.start();

 

If we execute the application, we can see that the application uses SAS for its communication. Similarly, any application that performs SNMP operations can be built.

 

Refer the source code of the following examples for more information.

 

Tutorial Available In

Example for the standalone application which uses SAS for communication

<examples/sasapps/sasapplication.java>

SNMP GET application which uses SAS for communication

<tutorials/sas_api/snmpget.java>



Copyright © 2012, ZOHO Corp. All Rights Reserved.