Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: fi/kvanttisofta/sms/SampleSmsApp.java


1   //
2   // Copyright (c) 2001 Kvanttisofta oy.  All rights reserved.
3   //
4   //
5   // a sample application demonstrating the use of SmsTerminal and
6   // the SMS PDU message classes.
7   // (aspa@users.sourceforge.net).
8   //
9   // $Id: SampleSmsApp.java,v 1.1.1.1 2001/04/18 04:19:00 aspa Exp $.
10  //
11  
12  package fi.kvanttisofta.sms;
13  
14  import java.io.*;
15  import java.util.*;
16  import fi.kvanttisofta.sms.*;
17  
18  public class SampleSmsApp implements SmsListenerInterface {
19  
20      public SampleSmsApp() {
21      }
22  
23      public static void main(String[] args) {
24    SampleSmsApp myApp = new SampleSmsApp();
25    SmsTerminal term = null;
26  
27    System.err.println("SampleSmsApp starting");
28  
29    String confFileName = "samplesmsapp.conf";
30    Properties conf = null;
31    FileInputStream confIn = null;
32    try {
33        File confFile = new File(confFileName);
34        confIn = new FileInputStream(confFile);
35        conf = new Properties();
36        conf.load(confIn);
37    } catch (IOException e) {
38        System.err.println("could not read " + confFileName + ": " + e);
39        System.exit(1);
40    } finally {
41        try {
42      if(confIn!=null) confIn.close();
43        } catch (IOException e) { ; }
44    }
45    System.err.println("- configuration read");
46  
47    String smsTerminalPort = conf.getProperty("smsterminalport");
48  
49    System.err.println("- connecting to SMS terminal. please wait.");
50    
51    try {
52        term = new SmsTerminal(smsTerminalPort, myApp);
53    } catch (Exception e) {
54        System.err.println("unable to create a SmsTerminal");
55        System.err.println("msg: " + e);
56        System.exit(1);
57    }
58    System.err.println("- connected to terminal");
59  
60    int i;
61    String line, number, message;
62    InputStreamReader isr = new InputStreamReader(System.in);
63    BufferedReader in = new BufferedReader(isr);
64  
65    System.err.println("incoming messages are printed on console");
66    System.err.println("you can type in messages of the following form:\n"+
67           "number:message");
68    System.err.println("e.g.:\n358985019963:hello, world");
69    System.err.println("");
70  
71    try {
72        while( (line = in.readLine()) != null) {
73      i = line.indexOf(":");
74      try {
75          number = line.substring(0, i);
76          message = line.substring(i+1, line.length());
77          System.err.println("msg: '"+number+"', '"+message+"'");
78          term.sendMessage(number, message);
79      } catch (StringIndexOutOfBoundsException e) {
80          System.err.println("msg format: number:message");
81      }
82        }
83    } catch (IOException e) {
84        ;
85    }
86  
87      }
88  
89      public void receiveSms(int statusCode, String errmsg,
90           SmsMsgIncoming msg) {
91  
92    if(statusCode == SmsTerminal.SC_OK) {
93        System.out.println("msg received: " + msg.toString());
94    } else {
95        System.err.println("error receiving SMS message: " + errmsg);
96    }
97      }
98  
99  }