private void DataRecieveWorker_DoWork(object sender, DoWorkEventArgs e) { logbox.Invoke((MethodInvoker) delegate { AddOutput("Started recieving!"); }); var dataIn = new byte[8192 * 32]; while (GameSocket.Connected) { try { var bytesRead = GameSocket.Receive(dataIn, dataIn.Length, SocketFlags.None); if (bytesRead != -1) { Response = new Response.Data(dataIn); CheckResponse(Response); logbox.Invoke((MethodInvoker) delegate { AddOutput("\nRecieved packet of " + Response.Params.Count + " params [" + bytesRead + " bytes]:\n" + Response.Params.Aggregate(string.Empty, (c, n) => c + (n.Type + ": " + n + "\n"))); }); } else { // -1 Bytes read should indicate the client shutdown on their end break; } } catch (SocketException) { // You could exit this loop depending on the SocketException } }
private void DataRecieveWorker_DoWork(object sender, DoWorkEventArgs e) { logbox.Invoke((MethodInvoker) delegate { AddOutput("Started recieving!"); }); var dataIn = new byte[8192 * 32]; while (GameSocket.Connected) { try { var bytesRead = GameSocket.Receive(dataIn, dataIn.Length, SocketFlags.None); if (bytesRead != -1) { Response = new Response.Data(dataIn); CheckResponse(Response); logbox.Invoke((MethodInvoker) delegate { AddOutput("\nRecieved packet of " + Response.Params.Count + " params [" + bytesRead + " bytes]:\n" + Response.Params.Aggregate("", (c, n) => c += (n.Type.ToString() + ": " + n.ToString()) + "\n")); }); } else { // -1 Bytes read should indicate the client shutdown on their end break; } } catch (SocketException) { // You could exit this loop depending on the SocketException } catch (ThreadAbortException) { MessageBox.Show("Fatal error with the socket!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } catch (Exception ex) { logbox.Invoke((MethodInvoker) delegate { AddOutput("Error: " + ex.Message + "\n\n" + ex.StackTrace); }); } } GameSocket?.Close(); }
public void CheckResponse(Response.Data resdata) { //If we haven't recieved anything return if (resdata == null) { return; } if (resdata.Params.First().Type == Net.Response.ParamType.Int32) { if ((ulong)((Response.Int_32)(resdata.Params.First())).Value == 0xFFFFFFFFCC00CC00) { varDGV.Invoke((MethodInvoker) delegate { for (int i = 2; i < resdata.Params.Count; i++) { if (i + 4 > resdata.Params.Count) { break; } var variable = new Net.Variable(); variable.byte1 = resdata.Params[i].ToString(); i++; variable.byte2 = resdata.Params[i].ToString(); i++; variable.Varname = resdata.Params[i].ToString(); i++; variable.Section = resdata.Params[i].ToString(); i++; variable.Value = resdata.Params[i].ToString(); Variables.Add(variable); } }); } } VarlistRecieved?.Invoke(this, null); }