• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            socketref,再見!高德

            https://github.com/adoggie

              C++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              246 Posts :: 4 Stories :: 312 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(54)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            接口定義: 
            1 interface IAuthServer{
            2     CallReturn_t userAuth(string user,string passwd,int device_type);
            3     CallReturn_t registerUser(UserRegisterInfo_t reginfo); // tested
            4 };
            定義認證服務器接口,userAuth()返回認證用戶的token

            接口服務實現: 
             1 import os,os.path,sys,struct,time,traceback,signal,threading,copy,base64
             2 import datetime,base64
             3 
             4 from datetime import datetime
             5 from base import *
             6 import tcelib as tce
             7 from showbox import *
             8 import utils.misc
             9 import utils.config
            10 import utils.cipher
            11 
            12 
            13 os.environ.setdefault("DJANGO_SETTINGS_MODULE""database.showbox.showbox.settings")
            14 
            15 from django.db import connection
            16 from django.db.models import Sum
            17 from django.db import transaction
            18 # import sns.core.models as cm
            19 import database.showbox.core.models as  core
            20 import database.showbox.nosql.models as nosql
            21 
            22 class AuthServerImpl(IAuthServer):
            23     def __init__(self,app):
            24         IAuthServer.__init__(self)
            25         self.app = app
            26 
            27     def userAuth(self, user, passwd, device_type, ctx):
            28         cr = CallReturn_t()
            29         try:
            30             r = core.User.objects.get(user=user,passwd=passwd)
            31             userinfo = {
            32                 "id":r.id,
            33                 "user":user,
            34                 "name":r.name,
            35                 "login_time":int(time.time()),
            36                 "user_type":SnsConsts.Authorized_User
            37             }
            38             token = utils.cipher.encryptToken(userinfo)
            39             cr.value = token
            40         except:
            41             print traceback.format_exc()
            42             cr = CallReturn_Error()
            43         return cr
            44 
            45     def registerUser(self, reginfo, ctx):
            46         return IAuthServer.registerUser(self, reginfo, ctx)
            47 
            48 
            49 
            50 class ServerApp:
            51     def __init__(self):
            52         pass
            53 
            54     def getConfig(self):
            55         #return self.app.getConfig()
            56         pass
            57 
            58     _handle = None
            59     @classmethod
            60     def instance(cls):
            61         if cls._handle == None:
            62             cls._handle = cls()
            63         return cls._handle
            64 
            65     def run(self):
            66         tce.RpcCommunicator.instance().init('authserver').initMessageRoute('./services.xml')
            67         server = tce.RpcCommunicator.instance().currentServer().findEndPointByName('mq_authserver').impl
            68         adapter  = tce.RpcAdapterEasyMQ.create('server',server)
            69         #沒有主動發送消息的情形
            70         servant = AuthServerImpl(self)
            71         adapter.addServant(servant)
            72         tce.RpcCommunicator.instance().waitForShutdown()
            73 
            74 if __name__ == '__main__':
            75     ServerApp.instance().run()

            服務器很簡單,實現接口IAuthService的功能函數,定義一個ServerApp,然后運行 

            客戶調用測試:

             1 from datetime import datetime
             2 from base import *
             3 import tcelib as tce
             4 from showbox import *
             5 import utils.misc
             6 import utils.config
             7 import utils.cipher
             8 
             9 
            10 def userAuthResult(result,prx):
            11     print result
            12 
            13 # queue:client 必須在調用服務器的write 隊列mq
            14 communicator =tce.RpcCommunicator.instance().init()
            15 conn = tce.RpcConnectionEasyMQ.create('127.0.0.1',12301,'queue:mq_authserver')
            16 local = tce.RpcConnectionEasyMQ.create('127.0.0.1',12301,'queue:mq_test_client',tce.AF_READ)
            17 conn.setLoopbackMQ(local)
            18 
            19 
            20 prx = IAuthServerPrx(conn)
            21 prx.userAuth_async('test','111111',1,userAuthResult)    #異步調用
            22 print prx.userAuth('test','111111',1)           #同步調用

            21,22行分別測試兩種調用模式


            client與server通過EasyMQ進行傳遞
            easyMQ是個最簡單的消息隊列實現







            posted on 2013-11-26 00:53 放屁阿狗 閱讀(2030) 評論(0)  編輯 收藏 引用 所屬分類: RpcTCEeasyMQ
            亚洲中文字幕久久精品无码APP | 久久人人爽人人爽人人片av高请| 亚洲精品乱码久久久久久不卡| 亚州日韩精品专区久久久| 久久久久国产精品麻豆AR影院| 久久伊人影视| 久久久久久亚洲Av无码精品专口| 久久99精品久久久久久动态图| 亚洲国产精品久久久久| 久久久久久久波多野结衣高潮| 精品熟女少妇av免费久久| 亚洲日本va午夜中文字幕久久| 日本强好片久久久久久AAA| 久久久噜噜噜久久中文字幕色伊伊| 国内精品人妻无码久久久影院导航| 国产成人综合久久精品尤物| 一本一道久久综合狠狠老| 久久综合视频网站| 99久久精品免费看国产| 久久精品国产亚洲AV大全| 久久国内免费视频| 精品久久久久成人码免费动漫| 久久精品国产一区| 乱亲女H秽乱长久久久| 久久国产精品偷99| 亚洲嫩草影院久久精品| 国产精品岛国久久久久| 久久精品天天中文字幕人妻| 亚洲女久久久噜噜噜熟女| 欧美久久久久久午夜精品| 国产精品女同一区二区久久| .精品久久久麻豆国产精品| 色婷婷综合久久久久中文 | 精品久久久久久中文字幕人妻最新| 久久久久九九精品影院| 精品久久久无码中文字幕天天| 久久国产乱子伦精品免费强| 国产午夜精品久久久久免费视 | 久久久久av无码免费网| 7777精品伊人久久久大香线蕉| 久久成人小视频|