Search in sources :

Example 1 with SimulatorPDUProcessor

use of org.smpp.smscsim.SimulatorPDUProcessor in project opensmpp by OpenSmpp.

the class Simulator method stop.

/**
 * Stops all the currently active sessions and then stops the listener.
 */
protected void stop() throws IOException {
    if (smscListener != null) {
        System.out.println("Stopping listener...");
        synchronized (processors) {
            int procCount = processors.count();
            SimulatorPDUProcessor proc;
            SMSCSession session;
            for (int i = 0; i < procCount; i++) {
                proc = (SimulatorPDUProcessor) processors.get(i);
                session = proc.getSession();
                System.out.print("Stopping session " + i + ": " + proc.getSystemId() + " ...");
                session.stop();
                System.out.println(" stopped.");
            }
        }
        smscListener.stop();
        smscListener = null;
        if (deliveryInfoSender != null) {
            deliveryInfoSender.stop();
        }
        System.out.println("Stopped.");
    }
}
Also used : SimulatorPDUProcessor(org.smpp.smscsim.SimulatorPDUProcessor)

Example 2 with SimulatorPDUProcessor

use of org.smpp.smscsim.SimulatorPDUProcessor in project opensmpp by OpenSmpp.

the class Simulator method logToScreen.

/**
 * Changes the log to screen status. If logging to screen,
 * an information about received and sent PDUs as well as about
 * connection attempts is printed to standard output.
 */
protected void logToScreen() {
    if (smscListener != null) {
        synchronized (processors) {
            displayInfo = !displayInfo;
            int procCount = processors.count();
            SimulatorPDUProcessor proc;
            for (int i = 0; i < procCount; i++) {
                proc = (SimulatorPDUProcessor) processors.get(i);
                proc.setDisplayInfo(displayInfo);
            }
        }
        factory.setDisplayInfo(displayInfo);
    }
}
Also used : SimulatorPDUProcessor(org.smpp.smscsim.SimulatorPDUProcessor)

Example 3 with SimulatorPDUProcessor

use of org.smpp.smscsim.SimulatorPDUProcessor in project opensmpp by OpenSmpp.

the class Simulator method listClients.

/**
 * Prints all currently connected clients on the standard output.
 */
protected void listClients() {
    if (smscListener != null) {
        synchronized (processors) {
            int procCount = processors.count();
            if (procCount > 0) {
                SimulatorPDUProcessor proc;
                for (int i = 0; i < procCount; i++) {
                    proc = (SimulatorPDUProcessor) processors.get(i);
                    System.out.print(proc.getSystemId());
                    if (!proc.isActive()) {
                        System.out.println(" (inactive)");
                    } else {
                        System.out.println();
                    }
                }
            } else {
                System.out.println("No client connected.");
            }
        }
    } else {
        System.out.println("You must start listener first.");
    }
}
Also used : SimulatorPDUProcessor(org.smpp.smscsim.SimulatorPDUProcessor)

Example 4 with SimulatorPDUProcessor

use of org.smpp.smscsim.SimulatorPDUProcessor in project opensmpp by OpenSmpp.

the class Simulator method sendMessage.

/**
 * Permits data to be sent to a specific client.
 * With the id of the client set by the user, the method <code>sendMessage</code>
 * gets back the specific reference to the client's <code>PDUProcessor</code>.
 * With this reference you are able to send data to the client.
 */
protected void sendMessage() throws IOException {
    if (smscListener != null) {
        int procCount = processors.count();
        if (procCount > 0) {
            String client;
            SimulatorPDUProcessor proc;
            listClients();
            if (procCount > 1) {
                System.out.print("Type name of the destination> ");
                client = keyboard.readLine();
            } else {
                proc = (SimulatorPDUProcessor) processors.get(0);
                client = proc.getSystemId();
            }
            for (int i = 0; i < procCount; i++) {
                proc = (SimulatorPDUProcessor) processors.get(i);
                if (proc.getSystemId().equals(client)) {
                    if (proc.isActive()) {
                        System.out.print("Type the message> ");
                        String message = keyboard.readLine();
                        DeliverSM request = new DeliverSM();
                        try {
                            request.setShortMessage(message);
                            proc.serverRequest(request);
                            System.out.println("Message sent.");
                        } catch (WrongLengthOfStringException e) {
                            System.out.println("Message sending failed");
                            event.write(e, "");
                        } catch (IOException ioe) {
                        } catch (PDUException pe) {
                        }
                    } else {
                        System.out.println("This session is inactive.");
                    }
                }
            }
        } else {
            System.out.println("No client connected.");
        }
    } else {
        System.out.println("You must start listener first.");
    }
}
Also used : SimulatorPDUProcessor(org.smpp.smscsim.SimulatorPDUProcessor) WrongLengthOfStringException(org.smpp.pdu.WrongLengthOfStringException) PDUException(org.smpp.pdu.PDUException) DeliverSM(org.smpp.pdu.DeliverSM)

Aggregations

SimulatorPDUProcessor (org.smpp.smscsim.SimulatorPDUProcessor)4 DeliverSM (org.smpp.pdu.DeliverSM)1 PDUException (org.smpp.pdu.PDUException)1 WrongLengthOfStringException (org.smpp.pdu.WrongLengthOfStringException)1