/// <summary> /// 输入包输入处理 /// </summary> /// <param name="Data"></param> void SocketManager_DataInput(byte[] Data) { ReadBytesV2 read = new ReadBytesV2(Data); int length; int cmd; if (read.ReadInt32(out length) && read.ReadInt32(out cmd) && length == read.Length) { PACKTYPE cmds=(PACKTYPE)cmd; switch (cmds) { case PACKTYPE.LogOnRes: //如果是Message类型数据包 LOGONRES ms; if (read.ReadObject<LOGONRES>(out ms)) { if (ms != null) { if (!ms.IsLogOn) //1登入失败 MessageBox.Show(ms.Msg); else if (ms.IsLogOn) //2登入成功 { Logins = true; //设置 LOGINS this.BeginInvoke(new EventHandler((o, p) => Close())); //关闭窗口 } } } break; } } }
private bool IsModified(PACKTYPE record) { //Type-specific routine that takes into account relationships that should also be considered //when deciding if there are unsaved changes. The entity properties also return true if the //record is new or deleted. return(record.IsModified(_context)); }
void DataOn(byte[] data, UserManager e) { //建立一个读取数据包的类 参数是数据包 //这个类的功能很强大,可以读取数据包的数据,并可以把你发送过来的对象数据,转换对象引用 ReadBytesV2 read = new ReadBytesV2(data); int lengt; //数据包长度,用于验证数据包的完整性 int cmd; //数据包命令类型 //注意这里一定要这样子写,这样子可以保证所有你要度的数据是完整的,如果读不出来 Raed方法会返回FALSE,从而避免了错误的数据导致崩溃 if (read.ReadInt32(out lengt) && read.Length == lengt && read.ReadInt32(out cmd)) { //read.Read系列函数是不会产生异常的 PACKTYPE cmdType = (PACKTYPE)cmd; //根据命令读取数据包 switch (cmdType) { case PACKTYPE.Data: { DATA tmp; if (read.ReadObject <DATA>(out tmp)) { LogOut(e.UserName + "数据命令:" + tmp.CMD); switch (tmp.CMD) { case "GET": { DATARES _var1 = new DATARES() { Type = 1, Res = new List <string>() }; _var1.Res.Add("数据1"); _var1.Res.Add("数据2"); _var1.Res.Add("数据3"); _var1.Res.Add("数据4"); _var1.Res.Add("数据5"); server.SendData(e.Asyn.AcceptSocket, BufferFormatV2.FormatFCA(_var1)); } break; } } } break; } } }
void LogOnPack(byte[] data, SocketAsyncEventArgs asyn) { ReadBytesV2 read = new ReadBytesV2(data); int lengt; //数据包长度,用于验证数据包的完整性 int cmd; //数据包命令类型 //注意这里一定要这样子写,这样子可以保证所有你要度的数据是完整的,如果读不出来 Raed方法会返回FALSE,从而避免了错误的数据导致崩溃 if (read.ReadInt32(out lengt) && read.Length == lengt && read.ReadInt32(out cmd)) { //read.Read系列函数是不会产生异常的 //根据命令读取数据包 PACKTYPE cmdType = (PACKTYPE)cmd; switch (cmdType) { case PACKTYPE.LogOn: { LOGON _logon; if (read.ReadObject <LOGON>(out _logon)) { //DOTO:验证用户 LogOut(_logon.username + " 登入成功"); UserManager tmp = new UserManager() { Asyn = asyn, Stream = new ZYNetRingBufferPoolV2(), UserName = _logon.username }; asyn.UserToken = tmp; userlist.Add(tmp); LOGONRES senddata = new LOGONRES() { IsLogOn = true, Msg = "登入成功" }; server.SendData(asyn.AcceptSocket, BufferFormatV2.FormatFCA(senddata)); } } break; } } }
void SetBindings() { //If the route list is filtered, there will be rows in the binding source //that are not visible, and they can become selected if the last visible row //is deleted, so handle that by checking rowcount. if (BindingSource.Current == null) { _selectedRecord = null; SetReadOnly(true); } else { _selectedRecord = ((PACKTYPE)BindingSource.Current); SetReadOnly(false); SetReadOnlyKeyFields(true); } ErrorProvider.Clear(); }
void client_DataOn(byte[] Data) { ReadBytesV2 read = new ReadBytesV2(Data); int length; int cmd; if (read.ReadInt32(out length) && read.ReadInt32(out cmd) && length == read.Length) { PACKTYPE cmds = (PACKTYPE)cmd; switch (cmds) { case PACKTYPE.DataRes: DATARES dox; if (read.ReadObject <DATARES>(out dox)) //获取服务器发送过来的 DATASET { if (dox != null) { this.BeginInvoke(new EventHandler((o, x) => { DATARES nn = o as DATARES; if (nn != null) { switch (nn.Type) { case 1: { foreach (string p in nn.Res) { this.richTextBox1.AppendText(p + "\r\n"); } } break; } } }), dox); } } break; } } }