Permalink
Browse files

Replaced thrift socket components with new SocketTransport class. Mov…

…ed files to new dir. Added feature to check for enquire link messages for transmitters as well
  • Loading branch information...
1 parent 61c99fc commit 3d1329a02f3f8bf08df4ddb4b7929d4574efed24 @duedal duedal committed Jul 22, 2011
View
@@ -17,13 +17,12 @@ To send a SMS you can do:
``` php
<?php
-$GLOBALS['SMPP_ROOT'] = dirname(__FILE__); // assumes this file is in the root
-require_once $GLOBALS['SMPP_ROOT'].'/protocol/smppclient.class.php';
-require_once $GLOBALS['SMPP_ROOT'].'/protocol/gsmencoder.class.php';
-require_once $GLOBALS['SMPP_ROOT'].'/transport/tsocket.class.php';
+require_once 'smppclient.class.php';
+require_once 'gsmencoder.class.php';
+require_once 'sockettransport.class.php';
// Construct transport and client
-$transport = new TSocket('your.smsc.com',2775);
+$transport = new SocketTransport(array('smpp.provider.com'),3600);
$transport->setRecvTimeout(10000);
$smpp = new SmppClient($transport);
@@ -37,11 +36,12 @@ $smpp->bindTransmitter("USERNAME","PASSWORD");
// Optional connection specific overrides
//SmppClient::$sms_null_terminate_octetstrings = false;
//SmppClient::$sms_use_msg_payload_for_csms = true;
+//SmppClient::$sms_registered_delivery_flag = SMPP::REG_DELIVERY_SMSC_BOTH;
// Prepare message
$message = 'H€llo world';
$encodedMessage = GsmEncoder::utf8_to_gsm0338($message);
-$from = new SmppAddress(GsmEncoder::utf8_to_gsm0338('SMPP Tést'),SMPP::TON_ALPHANUMERIC);
+$from = new SmppAddress(SMPP Test',SMPP::TON_ALPHANUMERIC);
$to = new SmppAddress(4512345678,SMPP::TON_INTERNATIONAL,SMPP::NPI_E164);
// Send
@@ -55,12 +55,11 @@ To receive a SMS (or delivery receipt):
``` php
<?php
-$GLOBALS['SMPP_ROOT'] = dirname(__FILE__); // assumes this file is in the root
-require_once $GLOBALS['SMPP_ROOT'].'/protocol/smppclient.class.php';
-require_once $GLOBALS['SMPP_ROOT'].'/transport/tsocket.class.php';
+require_once 'smppclient.class.php';
+require_once 'sockettransport.class.php';
// Construct transport and client
-$transport = new TSocket('your.smsc.com',2775);
+$transport = new SocketTransport(array('smpp.provider.com'),3600);
$transport->setRecvTimeout(60000); // for this example wait up to 60 seconds for data
$smpp = new SmppClient($transport);
@@ -85,9 +84,9 @@ Implementation notes
- You can't connect as a transceiver, otherwise supported by SMPP v.3.4
- The SUBMIT_MULTI operation of SMPP, which sends a SMS to a list of recipients, is not supported atm. You can easily add it though.
- - The thrift sockets will return false if the timeout is reached (after version 0.6.0).
+ - The sockets will return false if the timeout is reached on read() (but not readAll or write).
You can use this feature to implement an enquire_link policy. If you need to send enquire_link for every 30 seconds of inactivity,
- set a timeout of 30 seconds, and send the enquire_link command if readSMS() returns false.
+ set a timeout of 30 seconds, and send the enquire_link command after readSMS() returns false.
- The examples above assume that the SMSC default datacoding is [GSM 03.38](http://en.wikipedia.org/wiki/GSM_03.38).
- Remember to activate registered delivery if you want delivery receipts (set to SMPP::REG_DELIVERY_SMSC_BOTH / 0x01).
- Both the SmppClient and transport components support a debug callback, which defaults to error_log. Use this to redirect debug information.
File renamed without changes.
@@ -1,5 +1,5 @@
<?php
-require_once $GLOBALS['SMPP_ROOT'].'/transport/ttransport.class.php';
+require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'sockettransport.class.php';
/**
* Class for receiving or sending sms through SMPP protocol.
@@ -72,10 +72,10 @@ class SmppClient
/**
* Construct the SMPP class
*
- * @param TTransport $transport
+ * @param SocketTransport $transport
* @param string $debugHandler
*/
- public function __construct(TTransport $transport,$debugHandler=null)
+ public function __construct(SocketTransport $transport,$debugHandler=null)
{
// Internal parameters
$this->sequence_number=1;
@@ -457,6 +457,37 @@ public function enquireLink()
}
/**
+ * Respond to any enquire link we might have waiting.
+ * If will check the queue first and respond to any enquire links we have there.
+ * Then it will move on to the transport, and if the first PDU is enquire link respond,
+ * otherwise add it to the queue and return.
+ *
+ */
+ public function respondEnquireLink()
+ {
+ // Check the queue first
+ $ql = count($this->pdu_queue);
+ for($i=0;$i<$ql;$i++) {
+ $pdu=$this->pdu_queue[$i];
+ if($pdu->id==SMPP::ENQUIRE_LINK) {
+ //remove response
+ array_splice($this->pdu_queue, $i, 1);
+ $this->sendPDU(new SmppPdu(SMPP::ENQUIRE_LINK_RESP, SMPP::ESME_ROK, $pdu->sequence, "\x00"));
+ }
+ }
+
+ // Check the transport for data
+ if ($this->transport->hasData()) {
+ $pdu = $this->readPDU();
+ if($pdu->id==SMPP::ENQUIRE_LINK) {
+ $this->sendPDU(new SmppPdu(SMPP::ENQUIRE_LINK_RESP, SMPP::ESME_ROK, $pdu->sequence, "\x00"));
+ } else {
+ array_push($this->pdu_queue, $pdu);
+ }
+ }
+ }
+
+ /**
* Reconnect to SMSC.
* This is mostly to deal with the situation were we run out of sequence numbers
*/
@@ -514,7 +545,7 @@ protected function sendPDU(SmppPdu $pdu)
call_user_func($this->debugHandler, ' command_id : 0x'.dechex($pdu->id));
call_user_func($this->debugHandler, ' sequence number : '.$pdu->sequence);
}
- $this->transport->write($header.$pdu->body);
+ $this->transport->write($header.$pdu->body,$length);
}
/**
Oops, something went wrong.

0 comments on commit 3d1329a

Please sign in to comment.