Esempio n. 1
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);
       ProtoAttribute arr=  (ProtoAttribute)ClassUtil.GetAttribute(item,typeof(ProtoAttribute));
         if(arr!=null)
       Console.WriteLine(arr.value);
     }
     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. 2
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. 3
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();
             
		}