Esempio n. 1
0
        public override void OnMessage(USocket us, ByteBuf bb)
        {
            bb.ReaderIndex(us.getProtocol().HeaderLen());
            short cmd = bb.ReadShort();

            byte[] bs = bb.GetRaw();
            Statics.SetXor(bs, bb.ReaderIndex());
            MemoryStream stream = new MemoryStream(bs, bb.ReaderIndex(), bb.ReadableBytes());

            MessageQueueHandler.GetProtocolType(cmd);
            object    obj     = null;//ProtoBuf.Serializer.NonGeneric.Deserialize(MessageQueueHandler.GetProtocolType(cmd), stream);
            FieldInfo success = obj.GetType().GetField("success");

            if (success != null)
            {
                if ((bool)success.GetValue(obj) == true)
                {
                    MessageQueueHandler.PushQueue(cmd, obj);
                }
                else
                {
                    FieldInfo info = obj.GetType().GetField("info");
                    if (info != null)
                    {
                        Debug.LogWarning("下行出错, cmd=" + cmd + ", type=" + MessageQueueHandler.GetProtocolType(cmd).ToString());
                        MessageQueueHandler.PushError(info.GetValue(obj).ToString());
                    }
                }
            }
        }
Esempio n. 2
0
 public override void OnMessage(USocket us,ByteBuf bb)
 {
     Console.WriteLine ("收到数据:");
     bb.ReaderIndex (2);
     string s=bb.ReadUTF8 ();
     Console.WriteLine (s);
     bb.ReaderIndex (0);
     us.Send (bb);//原样返回给服务器,服务器是一个echo,也会原样返回
 }
Esempio n. 3
0
 public static void Main(string[] args)
 {
     SocketListner listner = new TestListner ();
     USocket us = new USocket ();
     us.setLister (listner);
     Protocal p = new LVProtocal ();
     us.setProtocal (p);
     us.Connect ("localhost", 3210);
     Console.Read();
 }
Esempio n. 4
0
        public override void OnMessage(USocket us, ByteBuf bb)
        {
            Console.WriteLine("收到数据:");
            bb.ReaderIndex(2);
            string s = bb.ReadUTF8();

            Console.WriteLine(s);
            bb.ReaderIndex(0);
            us.Send(bb);             //原样返回给服务器,服务器是一个echo,也会原样返回
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            SocketListner listner = new TestListner();
            USocket       us      = new USocket();

            us.setLister(listner);
            Protocal p = new LVProtocal();

            us.setProtocal(p);
            us.Connect("localhost", 3210);
            Console.Read();
        }
Esempio n. 6
0
        public override void OnMessage(USocket us, ByteBuf bb)
        {
            Console.WriteLine("收到数据:");
            bb.ReaderIndex(us.getProtocal().HeaderLen());

            int          cmd      = bb.ReadShort();
            MemoryStream stream   = new MemoryStream(bb.GetRaw(), bb.ReaderIndex(), bb.ReadableBytes());
            AuthResponse response = ProtoBuf.Serializer.Deserialize <AuthResponse>(stream);

            Console.WriteLine(response.pid);
            Console.WriteLine(response.info);
            Console.WriteLine(response.success);
        }
Esempio n. 7
0
        public override void OnOpen(USocket us)
        {
            Console.WriteLine ("连接建立");
            JsonData data = new JsonData ();
            data ["cmd"] = 1;
            data ["name"] = "你好";
            data ["pwd"] = "ldfkjl";

            Frame f = new Frame (512);
            f.PutString (data.ToJson());
            f.End ();
            us.Send (f);
        }
Esempio n. 8
0
        public override void OnMessage(USocket us,ByteBuf bb)
        {
            Console.WriteLine ("收到数据:");
            bb.ReaderIndex (us.getProtocal().HeaderLen());

            int cmd = bb.ReadShort();
            MemoryStream stream = new MemoryStream(bb.GetRaw(),bb.ReaderIndex(),bb.ReadableBytes());
            AuthResponse response= ProtoBuf.Serializer.Deserialize<AuthResponse>(stream);

            Console.WriteLine (response.pid);
            Console.WriteLine(response.info);
            Console.WriteLine(response.success);
        }
Esempio n. 9
0
		public override  void OnOpen(USocket us)
		{
			Console.WriteLine ("连接建立");
            AuthRequest request = new AuthRequest();
            request.loginid = "lkjlkj;sdf你好";
            request.serverid = 1;
            MemoryStream  stream = new MemoryStream();
            ProtoBuf.Serializer.Serialize<AuthRequest>(stream, request);

            Varint32Frame f = new Varint32Frame(512);
            f.PutShort(6);
            f.PutBytes(stream.ToArray());
            f.End();
			us.Send (f);
		}
Esempio n. 10
0
		public override  void OnMessage(USocket us,ByteBuf bb)
		{
			Console.WriteLine ("收到数据:");
			bb.ReaderIndex (us.getProtocal().HeaderLen());

            int cmd = bb.ReadShort();
            Type t=null;
            MemoryStream stream = new MemoryStream(bb.GetRaw(),bb.ReaderIndex(),bb.ReadableBytes());
            object response=ProtoBuf.Serializer.NonGeneric.Deserialize(t,stream);
            /**
			Console.WriteLine (response.pid);
            Console.WriteLine(response.info);
            Console.WriteLine(response.success);
            */
		}
Esempio n. 11
0
        public override void OnOpen(USocket us)
        {
            Console.WriteLine("连接建立");
            JsonData data = new JsonData();

            data ["cmd"]  = 1;
            data ["name"] = "你好";
            data ["pwd"]  = "ldfkjl";

            Frame f = new Frame(512);

            f.PutString(data.ToJson());
            f.End();
            us.Send(f);
        }
Esempio n. 12
0
        public override void OnMessage(USocket us, ByteBuf bb)
        {
            Console.WriteLine("收到数据:");
            bb.ReaderIndex(us.getProtocal().HeaderLen());

            int          cmd      = bb.ReadShort();
            Type         t        = null;
            MemoryStream stream   = new MemoryStream(bb.GetRaw(), bb.ReaderIndex(), bb.ReadableBytes());
            object       response = ProtoBuf.Serializer.NonGeneric.Deserialize(t, stream);

            /**
             *          Console.WriteLine (response.pid);
             * Console.WriteLine(response.info);
             * Console.WriteLine(response.success);
             */
        }
Esempio n. 13
0
        public override void OnOpen(USocket us)
        {
            Console.WriteLine("连接建立");
            AuthRequest request = new AuthRequest();

            request.loginid  = "lkjlkj;sdf你好";
            request.serverid = 1;
            MemoryStream stream = new MemoryStream();

            ProtoBuf.Serializer.Serialize <AuthRequest>(stream, request);

            Frame f = new Frame(512);

            f.PutShort(6);
            f.PutBytes(stream.ToArray());
            f.End();
            us.Send(f);
        }
Esempio n. 14
0
        public static void Main1(string[] args)
        {
            AuthRequest ar   = new AuthRequest();
            string      json = JsonMapper.ToJson(ar);

            Console.WriteLine(ar.GetType().Name + ":" + json);
            List <Type> ls = ClassUtil.GetClasses("protocol");

            foreach (Type item in ls)
            {
                Console.WriteLine(item.Name);
                ConstructorInfo constructor = item.GetConstructor(new Type[0]);
                //使用构造器对象来创建对象
                object obj = constructor.Invoke(new Object[0]);

                ProtoAttribute arr = (ProtoAttribute)ClassUtil.GetAttribute(item, typeof(ProtoAttribute));
                if (arr != null)
                {
                    Console.WriteLine(arr.value);
                }
            }
            Console.Read();

            /**
             * long time_JAVA_Long = 1446050129676L;//java长整型日期,毫秒为单位
             * DateTime dt_1970 = new DateTime(1970, 1, 1, 0, 0, 0);
             * long tricks_1970 = dt_1970.Ticks;//1970年1月1
             * long time_tricks = tricks_1970 + time_JAVA_Long * 10000;//日志日期刻度
             * DateTime dt = new DateTime(time_tricks).AddHours(8);//转化为DateTime
             * Console.WriteLine(string.Format("{0:G}", dt));
             * Console.Read();
             */
            SocketListner listner = new TestListner();
            USocket       us      = new USocket();

            us.setLister(listner);
            Protocal p = new Varint32HeaderProtocol();

            //Protocal p = new LVProtocal();
            us.setProtocal(p);
            us.Connect("localhost", 4887);
            Console.Read();
        }
Esempio n. 15
0
		public static void Main (string[] args)
		{
            
            AuthRequest ar = new AuthRequest();
            string json = JsonMapper.ToJson(ar);
            Console.WriteLine(ar.GetType().Name+":"+json);
            List<Type> ls = ClassUtil.GetClasses("protocol");
            foreach (Type item in ls)
            {
              Console.WriteLine(item.Name);
              ConstructorInfo constructor = item.GetConstructor(new Type[0]);
              //使用构造器对象来创建对象
              object obj = constructor.Invoke(new Object[0]);

              ProtoAttribute arr=  (ProtoAttribute)ClassUtil.GetAttribute(item,typeof(ProtoAttribute));
                if(arr!=null)
              Console.WriteLine(arr.value);
            }
            Console.Read();
            
             /**
            long time_JAVA_Long = 1446050129676L;//java长整型日期,毫秒为单位             
            DateTime dt_1970 = new DateTime(1970, 1, 1, 0, 0, 0);              
            long tricks_1970 = dt_1970.Ticks;//1970年1月1                 
            long time_tricks = tricks_1970 + time_JAVA_Long * 10000;//日志日期刻度    
            DateTime dt = new DateTime(time_tricks).AddHours(8);//转化为DateTime
            Console.WriteLine(string.Format("{0:G}", dt));
            Console.Read();
            */
			SocketListner listner = new TestListner ();
			USocket us = new USocket ();
			us.setLister (listner);
			Protocal p = new Varint32HeaderProtocol ();
            //Protocal p = new LVProtocal();
			us.setProtocal (p);
			us.Connect ("localhost", 4887);
			Console.Read();
             
		}
Esempio n. 16
0
        public static void Main(string[] args)
        {
            /**
             * AuthRequest ar = new AuthRequest();
             * ar.serverid = 1;
             * ar.userCode = "zs";
             * ar.testing = false;
             * ar.ucenterId = 1;
             * string json = JsonMapper.ToJson(ar);
             * Console.WriteLine(ar.GetType().Name + ":" + json);
             * List<Type> ls = ClassUtil.GetClasses("protocol");
             * foreach (Type item in ls)
             * {
             *  Console.WriteLine(item.Name);
             *  ConstructorInfo constructor = item.GetConstructor(new Type[0]);
             *  //使用构造器对象来创建对象
             *  object obj = constructor.Invoke(new Object[0]);
             *
             *  ProtoAttribute arr = (ProtoAttribute)ClassUtil.GetAttribute(item, typeof(ProtoAttribute));
             *  if (arr != null)
             *      Console.WriteLine(arr.value);
             * }
             * Console.Read();
             **/
            /**
             * long time_JAVA_Long = 1446050129676L;//java长整型日期,毫秒为单位
             * DateTime dt_1970 = new DateTime(1970, 1, 1, 0, 0, 0);
             * long tricks_1970 = dt_1970.Ticks;//1970年1月1
             * long time_tricks = tricks_1970 + time_JAVA_Long * 10000;//日志日期刻度
             * DateTime dt = new DateTime(time_tricks).AddHours(8);//转化为DateTime
             * Console.WriteLine(string.Format("{0:G}", dt));
             * Console.Read();
             */
            SocketListner listner = new TestListner();
            USocket       us      = new USocket();

            us.setLister(listner);
            //Protocal p = new Varint32HeaderProtocol ();
            Protocal p = new LVProtocal();

            us.setProtocal(p);
            us.Connect("119.29.189.247", 4887);
            //us.Connect("127.0.0.1", 4887);



            /*
             * MemoryStream stream = new MemoryStream();
             * ProtoBuf.Serializer.NonGeneric.Serialize(stream, ar);
             * byte[] bs = stream.ToArray();
             *
             * Frame f = new Frame(512);
             * f.PutShort(6);
             * Frame.xor(bs, System.Text.Encoding.UTF8.GetBytes("421w6tW1ivg="));
             *
             * f.PutBytes(bs);
             * f.End();
             * us.Send(f);
             **/
            Console.Read();
        }
Esempio n. 17
0
		/**
		 * 
		 */ 
		public override  void OnClose(USocket us,bool fromRemote)
		{
			Console.WriteLine ("连接被关闭:"+fromRemote);
		}
Esempio n. 18
0
		public override  void OnIdle(USocket us)
		{
			Console.WriteLine ("连接超时:");
		}
Esempio n. 19
0
		abstract public void OnOpen(USocket us);
Esempio n. 20
0
		abstract public void OnIdle(USocket us);
Esempio n. 21
0
 protected virtual void OnSocketOpened(USocket us)
 {
     SocketOpenedEvent?.Invoke(us);
 }
Esempio n. 22
0
 public override void OnOpen(USocket us)
 {
     Debug.LogWarning("连接建立, ip=" + us.getIp());
 }
Esempio n. 23
0
 /**
  *
  */
 public override void OnClose(USocket us, bool fromRemote)
 {
     MessageQueueHandler.PushError(fromRemote ? "与服务器连接已断开" : "关闭连接");
 }
Esempio n. 24
0
 abstract public void OnIdle(USocket us);
Esempio n. 25
0
 abstract public void OnMessage(USocket us, ByteBuf bb);
Esempio n. 26
0
 public override void OnError(USocket us, string err)
 {
     Console.WriteLine("错误:" + err);
 }
Esempio n. 27
0
 /**
  *
  */
 public override void OnClose(USocket us, bool fromRemote)
 {
     Console.WriteLine("连接被关闭:" + fromRemote);
 }
Esempio n. 28
0
 protected virtual void OnSocketClosed(USocket us, bool fromRemote)
 {
     SocketClosedEvent?.Invoke(this, new SocketCloseEventArg {
         Socket = us, FromRemote = fromRemote
     });
 }
Esempio n. 29
0
		public override  void OnError(USocket us,string err)
		{
			Console.WriteLine ("错误:"+err);
		}
Esempio n. 30
0
 public override void OnIdle(USocket us)
 {
     Console.WriteLine("连接超时:");
 }
Esempio n. 31
0
 protected virtual void OnSocketError(USocket us, string err)
 {
     SocketErrorEvent?.Invoke(this, new SocketErrorEventArg {
         Socket = us, Error = err
     });
 }
Esempio n. 32
0
 abstract public void OnError(USocket us, string err);
Esempio n. 33
0
 public abstract void OnIdle(USocket us);
Esempio n. 34
0
 abstract public void OnClose(USocket us, bool fromRemote);
Esempio n. 35
0
 public abstract void OnOpen(USocket us);
Esempio n. 36
0
 abstract public void OnOpen(USocket us);
Esempio n. 37
0
		abstract public void OnError(USocket us,string err);
Esempio n. 38
0
 public override void OnIdle(USocket us)
 {
     Debug.LogWarning("连接超时");
 }
Esempio n. 39
0
		abstract public void OnMessage(USocket us,ByteBuf bb);
Esempio n. 40
0
 public override void OnError(USocket us, string err)
 {
     Debug.LogWarning("异常:" + err);
 }
Esempio n. 41
0
		abstract public void OnClose(USocket us,bool fromRemote);