public IClientSender CreateClientSender <T>(T address)
     where T : JimuAddress
 {
     try
     {
         _logger.Debug($"creating transport client for: {address.Code}");
         //return Clients.GetOrAdd(address.CreateEndPoint(), ep => new Lazy<ITransportClient>(() =>
         var val = ClientSenders.GetOrAdd($"{address.Protocol}-{address.Code}", (ep => new Lazy <IClientSender>((() =>
         {
             IClientSender client = null;
             ClientSenderCreator?.Invoke(address, ref client);
             return(client);
         })))).Value;
         if (!val.CheckValid())
         {
             _logger.Debug($"transport client for: {address.Code} is invalid, retry to created");
             ClientSenders.TryRemove($"{address.Protocol}-{address.Code}", out _);
             val = ClientSenders.GetOrAdd($"{address.Protocol}-{address.Code}", (ep => new Lazy <IClientSender>((() =>
             {
                 IClientSender client = null;
                 ClientSenderCreator?.Invoke(address, ref client);
                 return(client);
             })))).Value;
         }
         _logger.Debug($"succed to create transport client for: {address.Code}");
         return(val);
     }
     catch (Exception ex)
     {
         //Clients.TryRemove(address.CreateEndPoint(), out _);
         ClientSenders.TryRemove($"{address.Protocol}-{address.Code}", out _);
         _logger.Error($"failed to create transport client for : {address.Code}", ex);
         throw new TransportException(ex.Message, ex);
     }
 }
Exemple #2
0
 public async Task Received(IClientSender sender, JimuTransportMsg message)
 {
     if (OnReceived == null)
     {
         return;
     }
     await OnReceived(sender, message);
 }
Exemple #3
0
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            TransportMsg msg = message as TransportMsg;

            IClientListener listener = context.Channel.GetAttribute(AttributeKey <IClientListener> .ValueOf(typeof(DefaultTransportClientFactory), nameof(IClientListener))).Get();
            IClientSender   sender   = context.Channel.GetAttribute(AttributeKey <IClientSender> .ValueOf(typeof(DefaultTransportClientFactory), nameof(IClientSender))).Get();

            listener.Received(sender, msg);
        }
        public DefaultTransportClient(IClientListener listener, IClientSender sender, ISerializer serializer, ILogger logger)
        {
            _listener   = listener;
            _sender     = sender;
            _serializer = serializer;
            _logger     = logger;

            _listener.OnReceived += ListenerOnReceived;
        }
    private void Awake()
    {
        socketObj = GameObject.Find("NetworkManager(Clone)")?.GetComponent <SocketObj>();
        if (socketObj == null)
        {
            return;
        }

        clientSender            = socketObj.socketClient;
        socketObj.OnDataInvoke += SocketObj_OnDataInvoke;

        carStatusUIObj = CoreLinker.GetComponent <CarStatusUIObj>();
    }
Exemple #6
0
        private Task ListenerOnReceived(IClientSender sender, JimuTransportMsg message)
        {
            _logger.Debug($"receive response of msg: {message.Id}");
            if (!_resultCallbackDic.TryGetValue(message.Id, out var task))
            {
                return(Task.CompletedTask);
            }

            if (message.ContentType != typeof(JimuRemoteCallResultData).FullName)
            {
                return(Task.CompletedTask);
            }
            task.SetResult(message);
            return(Task.CompletedTask);
        }
        private Task ListenerOnReceived(IClientSender sender, TransportMsg message)
        {
            _logger.Debug($"收到消息,消息id: {message.Id}");

            if (!_resultCallbackDic.TryGetValue(message.Id, out TaskCompletionSource <TransportMsg> task))
            {
                return(Task.CompletedTask);
            }

            if (message.ContentType != typeof(RemoteCallBackData).FullName)
            {
                return(Task.CompletedTask);
            }

            task.SetResult(message);
            return(Task.CompletedTask);
        }
Exemple #8
0
    private void Start()
    {
        SendCamTexture  = false;
        CamQuality      = 3;
        CarStatusObject = GameObject.Find("CarStatusObject");

        objcarDevice = CarStatusObject.GetComponent <ObjectCarDevice>();
        tracerObj    = CarStatusObject.GetComponent <GPSTracerObj>();

        baseCarDivice = objcarDevice.Basecardivice;
        camManager    = GameObject.Find("CamManager").GetComponent <CamManager>();

        socketObj               = GameObject.Find("NetworkManager(Clone)").GetComponent <SocketObj>();
        clientSender            = socketObj.socketClient;
        socketObj.OnDataInvoke += SocketObj_OnDataInvoke;
        StartCoroutine(SendInitData());
    }
Exemple #9
0
        public void NewConnection(IClientSender clientSender, IClientEvents clientEvents,ConnectionInfo connectionInfo)
        {
            Accept = connectionInfo.Accept;
            Path = connectionInfo.Path;
            Version = connectionInfo.Version;
            ClientSender = clientSender;
            clientEvents.OnMessage = (message) =>
                                                 {
                                                     HasNewMessage = true;
                                                     Message = Encoding.UTF8.GetString(message);
                                                 };

            clientEvents.OnClose = (reason) =>
                                                      {
                                                          HasClosedconnection = true;
                                                          CloseReasons.Add(reason);
                                                      };
            clientEvents.OnPing = (ping) =>
                                           {
                                               HasPing = true;
                                               PingMessage = ping;
                                           };
        }
Exemple #10
0
 public StartupTaskRunner(IRecipientRegistry recipientRegistry, IClientSender clientSender)
 {
     _recipientRegistry = recipientRegistry;
     _clientSender      = clientSender;
 }
Exemple #11
0
 public virtual void HandleHandshake(HandshakeServer e)
 {
     m_client       = e.Client;
     m_storageNodes = e.StorageNodes;
     Self.Active();
 }
Exemple #12
0
 public HandshakeServer(IClientSender client, IStorageNodeSender[] storageNode)
 {
     Client       = client;
     StorageNodes = storageNode;
 }
Exemple #13
0
 public ClientMessageProxy(IClientSender clientSender, string playerId)
 {
     _clientSender = clientSender;
     _playerId     = playerId;
     _channel      = "gamemessage";
 }
Exemple #14
0
 public ClientListener(NetworkStream client, IClientSender sender)
 {
     this.client = client;
     this.sender = sender;
 }
 public BaseClient(ulong _Id, SocketClient socketClient, bool _IsBot)
 {
     Id           = _Id;
     clientSender = socketClient;
     IsBot        = _IsBot;
 }