/*
 * Java implementation of the SMPP v3.3 API
 * Copyright (C) 1998 - 2000 by Oran Kelly
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
 * A copy of the LGPL can be viewed at http://www.gnu.org/copyleft/lesser.html
 * Java SMPP API author: orank@users.sf.net
 */

import java.util.Properties;
import java.io.FileInputStream;

import ie.omk.smpp.SMPPException;
import ie.omk.smpp.SmppTransmitter;
import ie.omk.smpp.net.TcpLink;
import ie.omk.smpp.message.*;
import ie.omk.smpp.util.*;

public class SyncTransmitter
{
    public static void main(String[] args)
    {
	try {
	    TcpLink link = new TcpLink("localhost", 5432);
	    SmppTransmitter trans = new SmppTransmitter(link);

	    Properties props = new Properties();
	    props.load(new FileInputStream("smpp.properties"));

	    String sysType = props.getProperty("esme.system_type");
	    String sysID = props.getProperty("esme.system_id");
	    String password = props.getProperty("esme.password");

	    SmeAddress source = new SmeAddress(
		    GSMConstants.GSM_TON_UNKNOWN,
		    GSMConstants.GSM_NPI_UNKNOWN,
		    props.getProperty("esme.destination"));
	    BindTransmitterResp btr = (BindTransmitterResp)trans.bind(sysID,
		    password, sysType, source);

	    if (btr.getCommandStatus() != 0) {
		System.err.println("Failed to bind to SMSC.");
		return;
	    }

	    System.out.println("Successfully bound to SMSC \"" +
		    btr.getSystemId() + "\"");

	    SmeAddress destination = new SmeAddress(
		    GSMConstants.GSM_TON_UNKNOWN,
		    GSMConstants.GSM_NPI_UNKNOWN,
		    "353861234567");

	    SubmitSM sm = new SubmitSM();
	    sm.setDestination(destination);
	    sm.setMessageText("This is a short message");
	    SubmitSMResp smr = (SubmitSMResp)trans.sendRequest(sm);

	    if (smr.getCommandStatus() != 0) {
		System.err.println("Error submitting message.");
	    } else {
		System.out.println("Message submitted. ID is \""
			+ smr.getMessageId() + "\"");
	    }

	    // Send a UCS2 encoded message...
	    sm = new SubmitSM();
	    sm.setDestination(new SmeAddress(
			GSMConstants.GSM_TON_UNKNOWN,
			GSMConstants.GSM_NPI_UNKNOWN,
			"434325425"));
	    sm.setMessageText("My ntrtnl message!",
		    new UCS2Encoding());
	    smr = (SubmitSMResp)trans.sendRequest(sm);
	    if (smr.getCommandStatus() != 0) {
		System.err.println("Error submitting UCS2 message");
	    } else {
		System.out.println("Message submitted. ID is \""
			+ smr.getMessageId() + "\"");
	    }

	    // Send a Binary encoded message...
	    sm = new SubmitSM();
	    sm.setDestination(new SmeAddress(
			GSMConstants.GSM_TON_UNKNOWN,
			GSMConstants.GSM_NPI_UNKNOWN,
			"434325425"));
	    byte[] msg = {
		(byte)0x45,
		(byte)0x32,
		(byte)0x22,
		(byte)0x57,
		(byte)0x12
	    };
	    sm.setMessage(msg, new BinaryEncoding());
	    smr = (SubmitSMResp)trans.sendRequest(sm);
	    if (smr.getCommandStatus() != 0) {
		System.err.println("Error submitting Binary message");
	    } else {
		System.out.println("Message submitted. ID is \""
			+ smr.getMessageId() + "\"");
	    }

	    System.out.println("Unbinding from SMSC...");

	    UnbindResp ubr = trans.unbind();
	    if (ubr.getCommandStatus() != 0) {
		System.err.println("Error occurred while unbinding from SMSC."
			+ " Code is " + ubr.getCommandStatus());
	    } else {
		System.out.println("Unbound. Closing network connection.");
	    }

	    link.close();
	} catch (SMPPException x) {
	    x.printStackTrace(System.err);
	} catch (java.io.IOException x) {
	    x.printStackTrace(System.err);
	}
    }
}

@@ -1247,16 +1247,18 @@
 tring%5B%5D 
+cl
 args)%0A  
@@ -1268,16 +1268,51 @@
 %0A%09try %7B%0A
+%09    Args args = new Args(clargs);%0A
 %09    Tcp
@@ -1339,25 +1339,32 @@
 ink(
-%22localhost%22, 5432
+args.hostName, args.port
 );%0A%09
@@ -1428,440 +1428,133 @@
     
-Properties props = new Properties();%0A%09    props.load(new FileInputStream(%22smpp.properties%22));%0A%0A%09    String sysType = props.getProperty(%22esme.system_type%22);%0A%09    String sysID = props.getProperty(%22esme.system_id%22);%0A%09    String password = props.getProperty(%22esme.password%22);%0A%0A%09    SmeAddress source = new SmeAddress(%0A%09%09    GSMConstants.GSM_TON_UNKNOWN,%0A%09%09    GSMConstants.GSM_NPI_UNKNOWN,%0A%09%09    props.getProperty(%22esme.destination%22)
+SmeAddress range = null;%0A%09    if (args.sourceRange != null)%0A%09%09range = new SmeAddress(args.ton, args.npi, args.sourceRange
 );%0A
+%0A
 %09   
@@ -1616,21 +1616,32 @@
 ind(
-sysID,
 %0A%09%09    
+args.sysID, args.
 pass
@@ -1646,16 +1646,21 @@
 ssword, 
+args.
 sysType,
@@ -1660,21 +1660,20 @@
 ysType, 
-sourc
+rang
 e);%0A%0A%09  

Use Args class to parse command line.