예제 #1
0
파일: SocketHelper.cs 프로젝트: whuacn/CJia
        /// <summary>
        /// 发送数据
        /// </summary>
        /// <param name="Msg"></param>
        public static async Task <object> SendMessage(Messages.ICJiaMessage Msg)
        {
            try
            {
                await ConnectServer();

                byte[] byteMsg  = SerializationMessage(Msg);
                byte[] byteSend = PrepareSendData(byteMsg);
                Writer.WriteBytes(byteSend);
                //发送消息
                await Writer.StoreAsync();

                //等待返回值
                var ResponseMsg = await WaitResponseMessage();

                if (ResponseMsg.RemoteException != null)
                {
                    throw ResponseMsg.RemoteException;
                }
                return(ResponseMsg.ReturnValue);
            }
            catch (Exception ex)
            {
                SocketErrorStatus ses = SocketError.GetStatus(ex.HResult);
                if (ses != SocketErrorStatus.Unknown)
                {
                    CloseConnection();
                }
                //SocketError.GetStatus(ex.HResult).ToString()
                MessageDialog msgDialog = new MessageDialog(ex.Message);
                msgDialog.ShowAsync();
                return(null);
            }
        }
예제 #2
0
파일: SocketHelper.cs 프로젝트: whuacn/CJia
 static byte[] SerializationMessage(Messages.ICJiaMessage Msg)
 {
     using (Serialization.SerializationWriter sw = new Serialization.SerializationWriter())
     {
         Msg.SerializeOwnedData(sw, null);
         return(sw.ToArray());
     }
 }