⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 receivemultipart.java

📁 控制手机发送短信程序
💻 JAVA
字号:
/*
 * $Id: ReceiveMultiPart.java,v 1.4 2005/09/01 13:27:17 huembi Exp $
 *
 * ====================================================================
 *
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * object XP AG ("Confidential Information"). You shall not disclose such
 * Confidential Information and shall use it only in accordance with
 * the terms of the license agreement you entered into with object XP AG.
 *
 * OBJECT XP AG MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE
 * SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. OBJECT XP AG
 * SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A
 * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 *
 * CopyrightVersion 1.0
 */
package sms;

import java.io.File;
import java.io.IOException;

import com.objectxp.msg.GsmSmsService;
import com.objectxp.msg.MessageEvent;
import com.objectxp.msg.MessageEventListener;
import com.objectxp.msg.MessageException;
import com.objectxp.msg.MultiPartReceiver;
import com.objectxp.msg.SmsService;


/**
 * This example demonstrates how to receive Multipart messages (like EMS
 * or Smart message) using jSMS. An incoming SMS, wich consist out of serveral parts,
 * will be cached internaly until all parts are received.
 *
 * The MultiPartReceiver concatenates the sms-parts together and transforms
 * them into the original format ({@link com.objectxp.msg.ems.EMSMessage} ,
 * {@link com.objectxp.msg.smart.SmartMessage}.
 *
 * Finaly, the {@link MyMessageEventListener} is informed about the arrival of
 * the complete SmsMessage.
 *
 * A incomming single part SMS will be broadcasted straight away to the listeners.
 */
public class ReceiveMultiPart
{

  public static int TIMEOUT = 60*1000;
  public static int MAX_ENTRIES = 200;

  public static void main(String args[]) throws IOException, MessageException
  {


    if(args.length != 1 ) {
      System.err.println("Usage: ReceiveMultiPart <config-file>");
      System.exit(1);
    }

    File config = new File(args[0]);

    // Create the SmsService (Replace GsmSmsService with
    // the SmsService Implementation of your choice).
    SmsService service = new GsmSmsService();

    // new event listener
    MessageEventListener listener = new MyMessageEventListener();

    // instantiate receiver with the cache limits.
    MultiPartReceiver receiver = new MultiPartReceiver(TIMEOUT, MAX_ENTRIES, listener);


    try {
      // get the service ready to listen for incoming messages
      service.init(config);
      // add the multipart receiver as listener to the service
      service.addMessageEventListener(receiver);
      service.connect();
      service.startReceiving();

      // manualy interupt the receiver
      System.out.print("Press any key to stop receiving messages");
      System.in.read();

      // stop listening for incoming sms's
      service.stopReceiving();
      service.disconnect();
    } finally {
      service.destroy();
      receiver.destroy();
    }
  }


  static class MyMessageEventListener implements MessageEventListener
  {
    // listening for incoming messages
    public void handleMessageEvent(MessageEvent event)
    {
      System.out.println("---------------------");
      System.out.println("MessageEvent: "+event);
    }
  }



}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -