예제 #1
0
 //发送消息(上线提醒)
 private void SendtoClientString(UserInfo user, string message)
 {
     var bytes = Encoding.UTF8.GetBytes(message);
     udpClient.Send(bytes, bytes.Length, user.RemoteIPEndpoint);
 }
예제 #2
0
 //登陆和退出
 private void SendMessageToServer(bool isLogin)
 {
     var userInfo = new UserInfo(this.txtUserName.Text, localEndPoint, isLogin);
     var bytes = SerializerHelper.ConvertObjectToBytes<UserInfo>(userInfo);
     udpClient.Send(bytes, bytes.Length, serverEndpointUdp);
 }
예제 #3
0
 //发送应答消息
 private void SendAcceptMessage(UserInfo user)
 {
     var loginInfo = new LoginInfo(true, tcpPort);
     //var messageStream = new MemoryStream();
     //new XmlSerializer(typeof(LoginInfo)).Serialize(messageStream, loginInfo);
     var messageBytes = SerializerHelper.ConvertObjectToBytes<LoginInfo>(loginInfo);
     udpClient.Send(messageBytes, messageBytes.Length, user.RemoteIPEndpoint);
 }