コード例 #1
0
ファイル: smpp_server.py プロジェクト: kashifpk/smpp5
    def start_serving(self, host, port):
        """
        This method is used by server to accept binding request of client on ip address on which server is listening
        and also creating seperate process to handle each client..
        """
        print("*** Seving on {host}:{port}".format(host=host, port=port))

        if '0.0.0.0' == host:  # translating all available ips to socket convention
            host = ''

        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # Create socket
        self.socket.bind((host, port))  # built-in method, bind with socket
        db.bind_session()  # Binding with database
        background_thread1 = threading.Thread(target=thread_4_incoming_sms, args=())  # Creating thread for handling incoming smses.
        background_thread1.start()  # Start thread which will run infintely unless smpp server stops.

        try:
            while True:
                self.socket.listen(1)  # listening for connections
                print("Zong server listening......")
                conn, addr = self.socket.accept()  # accept connections and return ip and port
                sc = SharedConnection(conn)
                sc.is_open = True

                P = multiprocessing.Process(target=handle_client_connection, args=(sc, addr))
                P.start()

                active_conns = multiprocessing.active_children()
                print("Total connections: %i" % len(active_conns))

        except (KeyboardInterrupt, SystemExit):
            print("Good bye!")
            background_thread1.join()
コード例 #2
0
ファイル: database_test.py プロジェクト: kashifpk/smpp5
import db
from db import DBSession
from models import User, Sms, Selected_package, User_Number, Prefix_Match
import hashlib
import transaction
from smpp5.lib.util.hex_print import hex_convert, hex_print
from smpp5.lib.parameter_types import Integer, CString, String, TLV
from smpp5.lib.pdu.session_management import *
from smpp5.lib.constants import interface_version as IV
from smpp5.lib.pdu.session_management import BindTransmitter, BindTransmitterResp, BindReceiver, BindReceiverResp, BindTransceiver, BindTransceiverResp, OutBind, UnBind, UnBindResp, EnquireLink, EnquireLinkResp, AlertNotification, GenericNack
from smpp5.lib.constants import *
from sqlalchemy import func
import datetime

if '__main__' == __name__:
    db.bind_session()
    d = datetime.date.today()-datetime.timedelta(days=4)
    S = Sms()
    S.sms_type = 'outgoing'
    S.sms_from = '+9233365195924'
    S.sms_to = '+923366767999'
    S.schedule_delivery_time = d   # give date 2nd december
    S.validity_period = d+datetime.timedelta(days=1)
    S.msg = "dont disturb.."
    S.timestamp = d
    S.status = 'delivered'
    S.msg_type = 'text'
    S.user_id = 'ASMA'
    S.package_name = 'dhamaka'
    S.rates = 0.0
    S.target_network = 'ufone'  # process sms file would use it to send to respective network of which server is.