Sieu ho tro Homepage
Forum Home Forum Home > Information Technology > The programming language > Java, Java script
  New Posts New Posts RSS Feed - package sms.gateway.process
  FAQ FAQ  Forum Search   Events   Register Register  Login Login


package sms.gateway.process

 Post Reply Post Reply
Author
Message Reverse Sort Order
administrator View Drop Down
Admin
Admin

ad

Joined: 14 October 2005
Status: Offline
Points: 510
Post Options Post Options   Thanks (0) Thanks(0)   Quote administrator Quote  Post ReplyReply Direct Link To This Post Topic: package sms.gateway.process
    Posted: 16 April 2009 at 21:12

package sms.gateway.process;

 
import smpp.*;
import smpp.pdu.*;

import sms.util.Queue;
import sms.util.FileTool;
import sms.common.*;
import sms.gateway.Gateway;
import java.io.IOException;

/**
 * For receiving PDUs from SMSC, in Sync mode
 * --> Only request PDUs are received.
 */
public class SMPPReceiver extends Thread {
    private static Logger logger = new Logger("SMPPReceiver");

    private PDU pdu = null;
    private DeliverSM dsm = null;
    private Queue requestQueue = null;


    public SMPPReceiver() {
        this.requestQueue = Gateway.getRequestQueue();
    }
    public void run() {
        while (Gateway.isRunning()) {
            try {
                //pdu = Gateway.getSessionR().receive(Preference.receiveTimeout);
                pdu = Gateway.getSessionR().receive();
                if (pdu == null) continue;

                if (pdu.isValid()) {
                    if (pdu.isRequest()) {
                        // Logger.println2C("==> " + pdu.debugString());

                        // Make default response
                        Response response = ( (Request) pdu).getResponse();

                        // Reply with default response
                        //Logger.println2C("<== " + response.debugString());
                        Gateway.getSessionR().respond(response);

                        // Add to requestQueue for further processing
                        if (pdu.getCommandId() != Data.ENQUIRE_LINK) {
                            if (pdu.getCommandId() == Data.DELIVER_SM) {
                                dsm = (DeliverSM) pdu;
                                logger.printPDU(dsm);
                                requestQueue.enqueue(pdu);
                            } else {
                                logger.info("Not a Deliver_SM: " + pdu.debugString());
                            }
                        }
                    } else if (pdu.isResponse()) {
                        // Process response
                        if (pdu.getCommandId() == Data.UNBIND_RESP) {
                            UnbindResp response = (UnbindResp) pdu;
                            logger.info("Unbind response " + response.debugString());
                            Gateway.setBoundR(false);
                            //System.exit(0);
                        } else {
                            logger.info("received a response(?), while expect requests only.");
                        }
                    } else {
                        logger.info(
                            "pdu of unknown class (not request nor response) " +
                            "received; Discarding " + pdu.debugString());
                    }
                } else {
                    logger.info("Received an invalid pdu: " + pdu);
                    String filename = "" + System.currentTimeMillis() + "_inv_pdu.dat";
                    logger.info("-->Save to file: " + filename);
                    try {
                        FileTool.saveToFile(pdu.getData().getBuffer(), filename, false);
                    } catch (ValueNotSetException ex) {
                        logger.error("handleEvent: " + ex.getMessage());
                    }
                }
            } catch (IOException ex) {
                logger.alert("DISCONNECTED from SMSC.");
                if (Gateway.isBound()) {
                    Gateway.setBound(false);
                    Gateway.setBoundR(false);
                    Gateway.bind();
                }
            } catch (Exception ex) {
                logger.error("run: " + ex.getMessage());
            }
        }
    }
}

Back to Top
Sponsored Links


Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.03
Copyright ©2001-2019 Web Wiz Ltd.

This page was generated in 0.172 seconds.
bao ky nam , Thuoc nam ky dieu
C?a thp ch?ng chy,cua thep chong chay,c?a ch?ng chy,cua chong chay,c?a nh?a abs,cua nhua abs,c?a abs,cua abs,cua thep van go,c?a thp vn g?,c?a thp an ton,cua thep an toan,c?a cu?n ch?ng chy,cua cuon chong chay,c?a g? ch?ng chy,cua go chong chay,c?a tru?t t? d?ng,cua truot tu dong,c?a knh ch?ng chy,cua kinh chong chay