Class: Smpp::Transmitter
- Defined in:
- lib/smpp/transmitter.rb
Overview
The SMPP Transmitter maintains a unidirectional connection to an SMSC. Provide a config hash with connection options to get started. See the sample_gateway.rb for examples of config values.
Constant Summary
Constants included from Smpp
Instance Attribute Summary collapse
-
#ack_ids ⇒ Object
readonly
Returns the value of attribute ack_ids.
Attributes inherited from Base
Instance Method Summary collapse
- #send_bind ⇒ Object
- #send_concat_mt(message_id, source_addr, destination_addr, message, options = {}) ⇒ Object
-
#send_mt(message_id, source_addr, destination_addr, short_message, options = {}) ⇒ Object
Send an MT SMS message.
Methods inherited from Base
#bound?, #initialize, #logger, logger, logger=, #post_init, #process_pdu, #receive_data, #run_callback, #send_unbind, #start_enquire_link_timer, #unbind, #unbound?
Constructor Details
This class inherits a constructor from Smpp::Base
Instance Attribute Details
#ack_ids ⇒ Object (readonly)
Returns the value of attribute ack_ids.
7 8 9 |
# File 'lib/smpp/transmitter.rb', line 7 def ack_ids @ack_ids end |
Instance Method Details
#send_bind ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/smpp/transmitter.rb', line 53 def send_bind raise IOError, 'Transmitter already bound.' unless unbound? pdu = Pdu::BindTransmitter.new( @config[:system_id], @config[:password], @config[:system_type], @config[:source_ton], @config[:source_npi], @config[:source_address_range]) write_pdu(pdu) end |
#send_concat_mt(message_id, source_addr, destination_addr, message, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/smpp/transmitter.rb', line 25 def send_concat_mt(, source_addr, destination_addr, , = {}) if @state == :bound # Split the message into parts of 134 characters. parts = [] while .size > 0 do parts << .slice!(0..133) end 0.upto(parts.size-1) do |i| udh = sprintf("%c", 5) # UDH is 5 bytes. udh << sprintf("%c%c", 0, 3) # This is a concatenated message udh << sprintf("%c", ) # The ID for the entire concatenated message udh << sprintf("%c", parts.size) # How many parts this message consists of udh << sprintf("%c", i+1) # This is part i+1 = { :esm_class => 64, # This message contains a UDH header. :udh => udh }.merge() pdu = Smpp::Pdu::SubmitSm.new(source_addr, destination_addr, parts[i], ) write_pdu(pdu) end else raise InvalidStateException, "Transmitter is unbound. Cannot send MT messages." end end |
#send_mt(message_id, source_addr, destination_addr, short_message, options = {}) ⇒ Object
Send an MT SMS message. Delegate will receive message_accepted callback when SMSC acknowledges, or the message_rejected callback upon error
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/smpp/transmitter.rb', line 11 def send_mt(, source_addr, destination_addr, , ={}) logger.debug "Sending MT: #{}" if @state == :bound pdu = Pdu::SubmitSm.new(source_addr, destination_addr, , ) write_pdu(pdu) # keep the message ID so we can associate the SMSC message ID with our message # when the response arrives. @ack_ids[pdu.sequence_number] = else raise InvalidStateException, "Transmitter is unbound. Cannot send MT messages." end end |