public static void Main(string[] args) { DoTcpMessageServerTest(); return; //do //{ // int key = Console.Read(); // if (key == 'q') break; //} while (true); //return; MsgUser user = new MsgUser() { from = "ahai", to = "gca", username = "******", role = "admin" }; byte[] msg = ProtobufSerializer.Serialize(user); MsgUser user1 = ProtobufSerializer.Deserialize(msg, 0, msg.Length) as MsgUser; MsgLogin login = new MsgLogin("ahai", "ysh19680215") { from = "ahai", to = "gca", }; byte[] msg2 = ProtobufSerializer.Serialize(login); MsgLogin login2 = (MsgLogin)ProtobufSerializer.Deserialize(msg2, 0, msg2.Length); return; }
public void OnUserLogin(object sender, MessageHeader msghdr) { TcpMessageChannel channel = (TcpMessageChannel)sender; MsgLogin login = (MsgLogin)msghdr; Log.Debug($"OnUserRegister() user:{login.username} password:{login.password}"); MsgText text = new MsgText($"user {login.username} login OK"); text.ackid = msghdr.id; channel.SendMessage(text); MsgFriendList friendlist = new MsgFriendList(); for (int i = 0; i < 10; i++) { MsgFriend friend = new MsgFriend() { friendid = i, friendname = $"friend{i}", groupname = $"group{i}", join_time = DateTime.Now }; friendlist.Friends.Add(friend); } channel.SendMessage(friendlist); }