internal static AppHead FromAppVer1(NETPACK_BASEHEAD_APPLICATION_VER1 appVer1) { AppHead head = new AppHead(); head.Channel = appVer1._channel; head.Encrypt = appVer1._encrypt; head.Compress = appVer1._compress; head.Format = appVer1._format; head.CodePage = appVer1._codepage; head.Identify = appVer1._identify; head.DataSize = appVer1._datasize; head.ValidSize = appVer1._validsize; head.Reserved = Helpers.ConvertByteArrayToString(appVer1._reserved); return(head); }
private void CheckConfigChangeWorker(IAsyncResult result) { var socket = result.AsyncState as Socket; if (socket == null) { OnDebug(LogMode.Error, string.Format("Socket is null")); return; } int intSize; try { intSize = socket.EndReceive(result); } catch (ObjectDisposedException) { return; } catch (Exception ex) { OnDebug(LogMode.Error, string.Format("End receive fail.\t{0}", ex.Message)); return; } if (intSize <= 0) { OnDebug(LogMode.Error, string.Format("Receive 0 length data")); return; } try { if (intSize < mDistHeadSize) { OnDebug(LogMode.Error, string.Format("Receive length invalid")); return; } //取出识别头 byte[] temp = new byte[mDistHeadSize]; Array.Copy(mBufferedData, 0, temp, 0, mDistHeadSize); DistHead distHead = (DistHead)Converter.Bytes2Struct(temp, typeof(DistHead)); OnDebug(LogMode.Info, string.Format("DistHead:{0}\t{1}", distHead.BaseHead, distHead.DataSize)); int baseHead = distHead.BaseHead; int dataSize = distHead.DataSize; if (baseHead != NETPACK_BASETYPE_APPLICATION_VER1) { OnDebug(LogMode.Error, string.Format("BaseHead invalid")); } else { if (intSize < mDistHeadSize + mAppHeadSize + dataSize) { OnDebug(LogMode.Error, string.Format("Receive length invalid")); return; } //取出基本头 byte[] baseData = new byte[mAppHeadSize]; Array.Copy(mBufferedData, mDistHeadSize, baseData, 0, mAppHeadSize); AppHead appHead = (AppHead)Converter.Bytes2Struct(baseData, typeof(AppHead)); OnDebug(LogMode.Info, string.Format("AppHead:{0}\t{1}", appHead.Encrypt, appHead.Format)); //取出数据区 byte[] dataData = new byte[dataSize]; Array.Copy(mBufferedData, mDistHeadSize + mAppHeadSize, dataData, 0, dataSize); string strMsg = Encoding.UTF8.GetString(dataData); OnDebug(LogMode.Info, string.Format("Data message:{0}", strMsg)); JsonObject jsonObject = new JsonObject(strMsg); if (jsonObject[NODE_NAME_PARAMCHANGE] != null) { if (jsonObject[NODE_NAME_PARAMCHANGE][NODE_NAME_MACHINEID] != null) { //获取MachineID string strID = jsonObject[NODE_NAME_PARAMCHANGE][NODE_NAME_MACHINEID].Value; if (strID == mLocalMachineID) { OnDebug(LogMode.Info, string.Format("Begin change config")); //Change config OnConfigChanged(); } } } } } catch (Exception ex) { OnDebug(LogMode.Error, string.Format("CheckConfigChangeWorker fail.\t{0}", ex.Message)); } try { socket.BeginReceive(mBufferedData, 0, ConstValue.NET_BUFFER_MAX_SIZE, SocketFlags.None, CheckConfigChangeWorker, socket); } catch (ObjectDisposedException) { } catch (Exception ex) { OnDebug(LogMode.Error, string.Format("Begin receive fail.\t{0}", ex.Message)); } }