2014-02-20 26 views
1

我已經從這個鏈接的github下載了源代碼:https://github.com/twitter/cloudhopper-smppCloudhopper SMPP - 如何獲取從其他客戶端發送的郵件內容?

假設我想測試客戶端之間的接收消息,所以我創建了一個服務器和2個客戶端。要運行服務器,我使用了命令「make server」。然後在另一臺機器,一個客戶端連接到我的服務器和發送1個消息,其中有電話號碼的其他客戶端「123456」使用下面的代碼

submit0.setSourceAddress(new Address((byte)0x03, (byte)0x00, "654321")); 
submit0.setDestAddress(new Address((byte)0x01, (byte)0x01, "123456")); 
submit0.setShortMessage(textBytes); 

SubmitSmResp submitResp = session0.submit(submit0, 10000); 

怎樣才能擁有電話號碼的客戶端「123456」得到的消息內容電話號碼「654321」?

謝謝!

回答

3

當你像這樣創建sessionHandler,

DefaultSmppSessionHandler sessionHandler = new ClientSmppSessionHandler(); 

這ClientSmppSessionHandler應該擴大到DefaultSmppSessionHandler。 共有2聽衆。 請看下面的例子。

public class ClientSmppSessionHandler extends DefaultSmppSessionHandler { 

private static final Logger logger = LoggerFactory.getLogger(ClientSmppSessionHandler.class); 

public ClientSmppSessionHandler() { 
    super(logger); 
} 

@Override 
public void firePduRequestExpired(PduRequest pduRequest) { 
    logger.warn("PDU request expired: {}", pduRequest); 
} 

@Override 
public PduResponse firePduRequestReceived(PduRequest pduRequest) { 
    PduResponse response = pduRequest.createResponse(); 
    logger.info("SMS Received: {}", pduRequest); 
    if (pduRequest.getCommandId() == SmppConstants.CMD_ID_DELIVER_SM) { 
     DeliverSm mo = (DeliverSm) pduRequest; 
     int length = mo.getShortMessageLength(); 
     Address source_address = mo.getSourceAddress(); 
     Address dest_address = mo.getDestAddress(); 
     byte[] shortMessage = mo.getShortMessage(); 
     String SMS= new String(shortMessage); 
     logger.info(source_address + ", " + dest_address + ", " + SMS); 
    } 
    return response; 
} 

}

相關問題