Esempio n. 1
0
        public virtual void Send(string uid, int contractID, IMessage body = null)
        {
            IChannel      channel       = this.userManager.GetChannel(uid);
            MessagePacket messagePacket = MessageCreater.CreateNormalMessage(GloblParams.DefaultServerID, uid, contractID, body);

            channel.WriteAndFlushAsync(messagePacket.ToByteBuffer());
        }
Esempio n. 2
0
        private void ResponseAck(IChannel channel, MessagePacket message)
        {
            MessagePacket returnMessage = new MessagePacket(GloblParams.DefaultServerID, message.MessageHeader.SourceUserID, message.MessageHeader.MessageID, (ClientType)message.MessageHeader.Client, MessageType.Ack_Resp, message.ContractID);
            var           buffer        = returnMessage.ToByteBuffer();

            channel.WriteAndFlushAsync(buffer);
        }
Esempio n. 3
0
        public virtual void Send2All(List <string> uids, int contractID, IMessage body = null)
        {
            MessagePacket          messagePacket = MessageCreater.CreateNormalMessage(GloblParams.DefaultServerID, GloblParams.CurrentClientID, contractID, body);
            IEnumerable <IChannel> channel       = this.userManager.GetChannel(uids);

            this.userManager.ClientChannelGroup.WriteAndFlushAsync(messagePacket.ToByteBuffer(), channel);
        }
Esempio n. 4
0
        private void ResponseQuery(IChannel channel, MessagePacket rawMessage, byte[] body)
        {
            MessagePacket messagePacket = new MessagePacket(rawMessage.MessageHeader.DestUserID, rawMessage.MessageHeader.SourceUserID, (ClientType)rawMessage.MessageHeader.Client, MessageType.Query_Resp, rawMessage.ContractID, body);
            IByteBuffer   byteBuffer    = messagePacket.ToByteBuffer();

            channel.WriteAndFlushAsync(byteBuffer);
        }
Esempio n. 5
0
 public virtual void Send(IChannel channel, int contractID, IMessage body = null)
 {
     if (channel != null)
     {
         MessagePacket messagePacket = MessageCreater.CreateNormalMessage(GloblParams.DefaultServerID, GloblParams.CurrentClientID, contractID, body);
         channel.WriteAndFlushAsync(messagePacket.ToByteBuffer());
     }
 }
Esempio n. 6
0
        internal virtual void Send(string uid, MessagePacket streamMessage)
        {
            IChannel channel = this.userManager.GetChannel(uid);

            if (channel != null)
            {
                channel.WriteAndFlushAsync(streamMessage.ToByteBuffer());
            }
        }
Esempio n. 7
0
        private void ResponseQuery(IChannel channel, byte type, MessagePacket rawMessage, byte[] body)
        {
            MessagePacket returnMessage = new MessagePacket(GloblParams.DefaultServerID, rawMessage.MessageHeader.SourceUserID,
                                                            rawMessage.MessageHeader.MessageID, (ClientType)rawMessage.MessageHeader.Client, type,
                                                            rawMessage.ContractID, body);

            var buffer = returnMessage.ToByteBuffer();

            channel.WriteAndFlushAsync(buffer);
        }
Esempio n. 8
0
        internal byte[] SendAckMessage(MessagePacket message)
        {
            TaskCompletionSource <byte[]> taskCompletionSource = new TaskCompletionSource <byte[]>();

            this.messageBag.TryAdd(message.MessageHeader.MessageID, taskCompletionSource);
            this.channel.WriteAndFlushAsync(message.ToByteBuffer(this.channel.Allocator.Buffer()));
            if (!taskCompletionSource.Task.Wait(GloblParams.WaitReplyTimeoutInSecs))
            {
                this.messageBag.TryRemove(message.MessageHeader.MessageID, out taskCompletionSource);
                throw new TimeoutException("timeout, cause by waiting for reply !");
            }
            this.messageBag.TryRemove(message.MessageHeader.MessageID, out taskCompletionSource);
            return(taskCompletionSource.Task.Result);
        }
Esempio n. 9
0
        internal void SendMessage <T>(MessagePacket message, Action <T> action) where T : IMessage <T>, new()
        {
            TaskCompletionSource <byte[]> taskCompletionSource = new TaskCompletionSource <byte[]>();

            this.messageBag.TryAdd(message.MessageHeader.MessageID, taskCompletionSource);
            this.channel.WriteAndFlushAsync(message.ToByteBuffer(this.channel.Allocator.Buffer()));
            taskCompletionSource.Task.ContinueWith((bytes) =>
            {
                MessageParser <T> messageParser = new MessageParser <T>(() => new T());
                T t = messageParser.ParseFrom(bytes.Result);
                action(t);
            });
            //if (!taskCompletionSource.Task.Wait(GloblParams.WaitReplyTimeoutInSecs))
            //{
            //    this.messageBag.TryRemove(message.MessageHeader.MessageID, out taskCompletionSource);
            //    throw new TimeoutException("timeout, cause by waiting for reply !");
            //}
            //this.messageBag.TryRemove(message.MessageHeader.MessageID, out taskCompletionSource);
            //var taskCompletionSource.Task.Result;
        }
Esempio n. 10
0
 internal void SendMessage(MessagePacket message)
 {
     this.channel.WriteAndFlushAsync(message.ToByteBuffer(this.channel.Allocator.Buffer()));
 }