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()); } } } }
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,也会原样返回 }
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(); }
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,也会原样返回 }
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(); }
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); }
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); }
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); }
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); }
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); */ }
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); }
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); */ }
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); }
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(); }
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(); }
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(); }
/** * */ public override void OnClose(USocket us,bool fromRemote) { Console.WriteLine ("连接被关闭:"+fromRemote); }
public override void OnIdle(USocket us) { Console.WriteLine ("连接超时:"); }
abstract public void OnOpen(USocket us);
abstract public void OnIdle(USocket us);
protected virtual void OnSocketOpened(USocket us) { SocketOpenedEvent?.Invoke(us); }
public override void OnOpen(USocket us) { Debug.LogWarning("连接建立, ip=" + us.getIp()); }
/** * */ public override void OnClose(USocket us, bool fromRemote) { MessageQueueHandler.PushError(fromRemote ? "与服务器连接已断开" : "关闭连接"); }
abstract public void OnMessage(USocket us, ByteBuf bb);
public override void OnError(USocket us, string err) { Console.WriteLine("错误:" + err); }
/** * */ public override void OnClose(USocket us, bool fromRemote) { Console.WriteLine("连接被关闭:" + fromRemote); }
protected virtual void OnSocketClosed(USocket us, bool fromRemote) { SocketClosedEvent?.Invoke(this, new SocketCloseEventArg { Socket = us, FromRemote = fromRemote }); }
public override void OnError(USocket us,string err) { Console.WriteLine ("错误:"+err); }
public override void OnIdle(USocket us) { Console.WriteLine("连接超时:"); }
protected virtual void OnSocketError(USocket us, string err) { SocketErrorEvent?.Invoke(this, new SocketErrorEventArg { Socket = us, Error = err }); }
abstract public void OnError(USocket us, string err);
public abstract void OnIdle(USocket us);
abstract public void OnClose(USocket us, bool fromRemote);
public abstract void OnOpen(USocket us);
abstract public void OnError(USocket us,string err);
public override void OnIdle(USocket us) { Debug.LogWarning("连接超时"); }
abstract public void OnMessage(USocket us,ByteBuf bb);
public override void OnError(USocket us, string err) { Debug.LogWarning("异常:" + err); }
abstract public void OnClose(USocket us,bool fromRemote);