Exemple #1
0
        /// 创建session
        public async Task <SessionIce> CreateSession(string ip, int port)
        {
            //设置locator
            var locator = LocatorPrxHelper.uncheckedCast(Communicator.stringToProxy("FootStone/Locator:default -h " + ip + " -p " + port));

            Communicator.setDefaultLocator(locator);

            //获取session factory
            var tmpconid          = Guid.NewGuid().ToString("N");
            var sessionFactoryPrx = ISessionFactoryPrxHelper
                                    .uncheckedCast(Communicator.stringToProxy("sessionFactory")
                                                   .ice_locatorCacheTimeout(0)
                                                   .ice_connectionId(tmpconid)
                                                   .ice_timeout(15000));

            //建立网络连接,设置心跳为30秒
            Connection connection = await sessionFactoryPrx.ice_getConnectionAsync();

            connection.setACM(30, ACMClose.CloseOff, ACMHeartbeat.HeartbeatAlways);
            NLogger.Debug(connection.getInfo().connectionId + " session connection:Endpoint=" + connection.getEndpoint().ToString());

            //添加push Prx
            var sessionPushI = new SessionPushI();
            var proxy        = ISessionPushPrxHelper.uncheckedCast(Adapter.addWithUUID(sessionPushI));

            foreach (var proto in iceClientOptions.PushObjects)
            {
                Adapter.addFacet(proto.push, proxy.ice_getIdentity(), proto.name);
            }

            //监听连接断开事件,并且绑定该连接到adapter
            connection.setCloseCallback(_ =>
            {
                NLogger.Warn($"{tmpconid} connecton closed!");
                sessionPushI.SessionDestroyed();
            });
            connection.setAdapter(Adapter);

            //创建session,并且注册push Prx到服务器
            await sessionFactoryPrx.CreateSessionAsync(proxy);

            return(new SessionIce(sessionFactoryPrx, sessionPushI));
        }
Exemple #2
0
 public SessionIce(ISessionFactoryPrx sessionPrx, SessionPushI sessionPush)
 {
     this.SessionPrx  = sessionPrx;
     this.SessionPush = sessionPush;
 }