- /* $Id: sasappclient.java,v 1.3.2.3 2009/01/28 12:55:03 prathika Exp $ */
- /*
- * @(#)sasappclient.java
- * Copyright (c) 1996-2009 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- /**
- * This Applet invokes the SASClient userSyncSend() method
- * to send a datas to the Server to perform some operation.
- * It receives the response data and print it.
- * It sends and receives the data continuously.
- */
- import java.applet.*;
- import java.lang.*;
- import java.awt.*;
- import java.awt.event.*;
- import com.adventnet.snmp.snmp2.*;
- public class sasappclient extends Applet implements ActionListener {
- TextArea text;
- TextField field;
- SASClient sasclient;
- public void init() {
- text = new TextArea( 10, 40);
- text.setEditable(false);
- Panel northPanel = new Panel();
- northPanel.add(new Label("Enter Message to Send: "));
- northPanel.add(field = new TextField(20));
- Panel southPanel = new Panel();
- Button sendButton = new Button("Send");
- southPanel.add(sendButton);
- sendButton.addActionListener(this);
- Button clearButton = new Button("Clear");
- southPanel.add(clearButton);
- clearButton.addActionListener(this);
- setLayout(new BorderLayout());
- add("North", northPanel);
- add("Center", text);
- add("South", southPanel);
- initSnmp();
- }
- void initSnmp() {
- // establish connection with the SAServer
- try {
- sasclient = new SASClient(this, true);
- sasclient.start();
- }
- catch (Exception e) {
- text.append("Error : " + e.getMessage() + "n");
- }
- }
- void sendData(String msg) {
- // Now let us use the UserSyncSend to send and receive
- // data to the application on the SAServer end
- byte data[] = msg.getBytes();
- byte resp_data[] = null;
- /* userSyncSend invoked .
- @param requestType = knownSASTypes+1;
- return Response data
- */
- if(sasclient != null) {
- int req_type = (sasclient.getMaxSasTypes())+1;
- resp_data = sasclient.userSyncSend (req_type, data);
- }
- else {
- text.append("SAServer not connected"+"n");
- return;
- }
- if (resp_data == null) {
- text.append("No response received from Server"+"n");
- return;
- }
- String res_msg = "";
- try
- {
- res_msg = new String(resp_data, SnmpAPI.ENCODING);
- }
- catch(Exception exp)
- {
- }
- text.append("Response Message:n" + res_msg + "n");
- }
- public void actionPerformed(ActionEvent e) {
- if(e.getActionCommand().equals("Send")) {
- sendData(field.getText());
- }
- else if(e.getActionCommand().equals("Clear")) {
- text.setText("");
- }
- }
- public void stop() {
- if(sasclient != null) {
- sasclient.stop();
- sasclient = null;
- }
- }
- }