Ejemplo n.º 1
0
def handle_client_connection(conn, addr):
    """
    This method is responsible to Handle a client connection and creating two background threads...One for handling
    client request pdus and other for delivering smses to client..
    """

    print("Accepted connection from: " + repr(addr))
    server_session = SMPPSession('server', conn)
    server_session.server_db_store = SMPPServer.db_storage
    server_session.server_validate_method = SMPPServer.validate
    server_session.server_query_result = SMPPServer.query_result
    server_session.server_cancel_result = SMPPServer.cancel_result
    server_session.server_replace_result = SMPPServer.replace_result
    server_session.sever_fetch_sms = fetch_incoming_sms
    server_session.commit_db = commit_db

    # background thread 1 to handle client request pdus by recieving them from socket and storing them in dictionary
    background_thread = threading.Thread(target=handle_client_requests, args=(server_session, conn))
    background_thread.start()

    # background thread 2 to check database for messages after every 5secs and deliever smses to client if any

    background_thread2 = threading.Thread(target=deliver_sms, args=(server_session, conn))
    background_thread2.start()

    # parent thread
    # current thread for sending responses to client
    while server_session.state != SessionState.UNBOUND:
        server_session.handle_pdu()

    conn.close()
    #time.sleep(1)
    background_thread.join()
    background_thread2.join()
Ejemplo n.º 2
0
class SMPPClient(object):
    '''
    Client Class is responsible to encode PDUs and send them to Server and also decode the response get from Server
    '''

    ip = None
    port = None
    system_id = None
    password = None
    system_type = None
    bind_mode = None
    session = None
    sc = None

    def __init__(self, ip, port):
        self.ip = ip
        self.port = port

    def connect(self):
        try:
            self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.socket.connect((self.ip, self.port))
            self.sc = SharedConnection(self.socket)
            self.sc.is_open = True
            self.session = SMPPSession('client', self.sc)
        except:
            return False

        return True

    def login(self, bind_mode, system_id, password, system_type):
        ret = False
        self.bind_mode = bind_mode
        self.system_id = system_id
        self.password = password
        self.system_type = system_type
        if SessionState.OPEN == self.session.state:
            self.session.bind(self.bind_mode, self.system_id, self.password, self.system_type)
            time.sleep(2)  # waiting for response for login because other actions can't be performed without login.
            self.session.processing_recieved_pdus()  # read pdu from dictionary, and change the status of session accordingly if ack is positive.
            if self.session.state in [SessionState.BOUND_RX, SessionState.BOUND_TX, SessionState.BOUND_TRX]:
                return True

        return ret
Ejemplo n.º 3
0
    def connect(self):
        try:
            self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.socket.connect((self.ip, self.port))
            self.sc = SharedConnection(self.socket)
            self.sc.is_open = True
            self.session = SMPPSession('client', self.sc)
        except:
            return False

        return True