def main(): global client, is_running client = smpplib.client.Client(CLIENT_IP, CLIENT_PORT) # Print Output and Start Handler client.set_message_sent_handler( lambda pdu: logging.info('sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler(handle_incoming_sms) client.connect() # Since bind was sucessful, we assume the show started. is_running = True t = Thread(target=process_sms_queue) t.start() while True: try: client.bind_transceiver(system_id=SYSTEM_ID, password=PASSWORD) print("LED_WALL: Successfully bound SMPP") client.listen() break except AttributeError: print("Binding to smpp service FAILED. Retrying.") continue except KeyboardInterrupt: break except Exception as e: logging.exception('Error during listen' + str(e)) is_running = False
def start(self): print("INSIDE start") global client global totMsg global pdu, data data = workerClass().getRadisData() workerClass().red.set("time", data["timeStamp"]) key_pause = str(data["timeStamp"]) + "_pause" workerClass().red.set(key_pause, "0") key_stop = str(data["timeStamp"]) + "_stop" workerClass().red.set(key_stop, "0") print(data["ip"]) client = workerClass().connectSmppClient(data["ip"], (int)(data["portNumber"])) try: workerClass().sendBindTransceiver(client, data["systemId"], data["password"], data["systemType"]) except Exception as e: print(e) sendingMessageThread = threading.Thread( target=workerClass().sendShortMessage, args=(client, data)) sendingMessageThread.start() sendingMessageThread.join() client.set_message_sent_handler(workerClass().getResponse) recevingMessageThread = threading.Thread(target=client.listen()) recevingMessageThread.start() recevingMessageThread.join()
def smpp_bind(client): while True: try: smpplib.client.logger.setLevel('INFO') client.set_message_received_handler(rx_deliver_sm) client.set_message_sent_handler(post_tx_message) #client.set_test_handler(my_test) #client.disconnect() client.connect() # Bind to OSMPP, out configured default-route in nitb. client.bind_transceiver(system_id="OSMPP", password="******") #client.test_handler(client, foo="bar") log.info('Listening....') client.listen([11]) except smpplib.exceptions.ConnectionError as e: print ("Connection Error (%s)" % e) client.disconnect() time.sleep(1)
def smpp_bind(client): while True: try: smpplib.client.logger.setLevel('INFO') client.set_message_received_handler(rx_deliver_sm) client.set_message_sent_handler(post_tx_message) #client.set_test_handler(my_test) #client.disconnect() client.connect() # Bind to OSMPP, out configured default-route in nitb. client.bind_transceiver(system_id="OSMPP", password="******") #client.test_handler(client, foo="bar") log.info('Listening....') client.listen([11]) except smpplib.exceptions.ConnectionError as e: print("Connection Error (%s)" % e) client.disconnect() time.sleep(1)
def bind_client(): logging.basicConfig(level='DEBUG') client = smpplib.client.Client('10.99.101.246', 2775) def getPdu(pdu): print(pdu.short_message.decode('utf-8')) print(type(pdu)) sql.save_des(randint(1, 1000000), "orginnn", pdu.short_message.decode('utf-8'),pdu.receipted_message_id) sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id)) client.set_message_received_handler( lambda pdu: getPdu(pdu)) client.set_message_sent_handler( lambda pdu: sys.stdout.write('sent {}\n'.format(pdu.receipted_message_id))) client.connect() client.bind_transceiver(system_id='rekik', password='******') client.listen() t = Thread(target=client.listen, args=()) t.daemon = True t.start() t.join() return
def handle(self, *args, **options): logging.basicConfig(level='DEBUG') try: op = options['op'] s = settings.SMPP[op] except: logging.error("no such config") exit() timeout = 15 if options['op'] == 'megafon': timeout = 60 client = smpplib.client.Client(s['ip'], s['port'], timeout) client.set_message_received_handler(mkGetPdu(op)) client.set_message_source(mkGenMessages(op, s['source'])) client.connect() client.bind_transceiver(system_id=s['system_id'], password=s['password']) try: client.listen([11]) except Exception as e: logging.error(e)
def main(): global client, messages f = open(MSG_FILE) logging.info('Opened file: {0!s}'.format(MSG_FILE)) for l in f: line = l.rstrip() splitted = line.split('|') time_range = splitted[0].split('-') one_line = [int(time_range[0]), int(time_range[1]), splitted[1]] messages.append(one_line) logging.info('file read and parsed') client = smpplib.client.Client(CLIENT_IP, CLIENT_PORT) # Print Output and Start Handler client.set_message_sent_handler(lambda pdu: logging.info( 'sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler(handle_incoming_sms) client.connect() while True: try: client.bind_transceiver(system_id=SYSTEM_ID, password=PASSWORD) print("MSGOFTHEDAY: Successfully bound SMPP") client.listen() logging.error('listend failed') break except KeyboardInterrupt: break except AttributeError: logging.error('Bind failed starting again.') continue except Exception as e: logging.exception('Error during listen' + str(e))
def send_to_jasmin_smpp_server(sender, reciver, message): logging.basicConfig(level='DEBUG') parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(message * 10) client = smpplib.client.Client('10.99.101.246', 2775) client.set_message_sent_handler( lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler( lambda pdu: sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id))) client.connect() client.bind_transceiver(system_id='rekik', password='******') for part in parts: pdu = client.send_message( source_addr_ton=smpplib.consts.SMPP_TON_INTL, # source_addr_npi=smpplib.consts.SMPP_NPI_ISDN, # Make sure it is a byte string, not unicode: source_addr=sender, dest_addr_ton=smpplib.consts.SMPP_TON_INTL, # dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN, # Make sure thease two params are byte strings, not unicode: destination_addr=reciver, short_message=part, data_coding=encoding_flag, esm_class=msg_type_flag, registered_delivery=True, ) print(pdu.sequence) t = Thread(target=client.listen()) t.start()
#!/usr/bin/python3.5 import logging import sys import smpplib.gsm import smpplib.client import smpplib.consts #if you want to know what's happening #logging.basicConfig(level='DEBUG') # Two parts, UCS2, SMS with UDH parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(u'Привет мир!\n' * 10) client = smpplib.client.Client('172.16.29.10', 2775) # Print when obtain message_id client.set_message_sent_handler(lambda pdu: sys.stdout.write( 'sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler(lambda pdu: sys.stdout.write( 'delivered {}\n'.format(pdu.receipted_message_id))) client.connect() client.bind_transceiver(system_id='asiatec', password='******') client.listen()
def send_info(pdu): log.info(pdu.__dict__) request_analyze_v.request(client, pdu) while 1: try: client = connect() request_analyze_v.list_of_objects = {} if client: client.set_message_received_handler( lambda pdu: send_info(pdu)) # thr = Thread(target=client.listen) # thr.start() client.listen() # except AttributeError: # time.sleep(20) # continue else: time.sleep(20) continue except Exception as err: log.info('Error in connection: {}'.format(err.message)) time.sleep(20) continue
def smpp_bind(): client = smpplib.client.Client("127.0.0.1", 2775, 90) client.set_message_received_handler(rx_alert_notification) client.connect() client.bind_transceiver(system_id="NOTIFY", password="******") client.listen()
def smpp_bind(): client = smpplib.client.Client("127.0.0.1", 2775, 90) client.set_message_received_handler(rx_alert_notification) client.connect() client.bind_transceiver(system_id="NOTIFY", password="******") client.listen()