Exemple #1
0
def connect_to_server(ip, port, system_id, password, system_type, recipient, message, sms_id, sender_number):
    """
    This method is responsible to create client instance to communicate with destination network server as client.
    """
    try:
        client = SMPPClient(ip, port)
        connection = False
        notification = 0
        while connection is False:   # while connection is not established with server, try to connect.
            if client.connect():
                connection = True
                # this thread is checking the socket for getting responses from other server and save in dictionary.
                background_thread4 = threading.Thread(target=client.session.storing_recieved_pdus, args=())  # to recieve pdu response from other smpp server to whom it has sent the request.
                background_thread4.start()
    
        if client.login('TX', system_id, password, system_type):  # if client successfully logins
            client.session.send_sms(recipient, message, sender_number)
            # till client receives  no response for sending sms
            while notification == 0:
                notification = client.session.notifications_4_client()
            client.session.processing_recieved_pdus()
        smses = DBSession.query(Sms).filter_by(id=int(sms_id)).first()
        if smses:
            smses.status = 'delivered'
        client.session.unbind()
        while client.session.state != SessionState.UNBOUND:
            client.session.processing_recieved_pdus()
        client.sc.close()
        transaction.commit()
        background_thread4.join()
    except:
        pass
Exemple #2
0
        return False

    ret['system_id'] = input("Enter the System Id       ")
    ret['password'] = input("Enter the Password        ")
    ret['system_type'] = input("Enter the System Type     ")

    return ret


if __name__ == '__main__':

    conn_info = get_connect_info()

    login = False

    client = SMPPClient(conn_info['ip'], conn_info['port'])

    if client.connect():
        print("\nConnection established successfully\n")
        background_thread = threading.Thread(target=client.session.storing_recieved_pdus, args=())  # to recieve response from server
        background_thread.start()
    else:
        print("\nConnection Refused...Try Again\n")
        sys.exit()

    while login is False:
        login_info = get_login_info()
        if client.login(login_info['bind_type'], login_info['system_id'], login_info['password'], login_info['system_type']):
            print("\nLogin successful")
            login = True
            ui_loop(client)  # to check if ui_loop method is functioning correct