public void OnMsg(byte[] msg) { Console.WriteLine("receive from server!"); Console.WriteLine(msg.Length); BinParser par = new BinParser(msg, 0); Console.WriteLine(par.Int()); Console.WriteLine(par.String()); }
public static string ReplaceEscapedValues(string text) { var matcher = new Matcher(); if (matcher.IsMatch(text, "'`x_' /(['0-9a-f_']+)")) { for (var i = 0; i < matcher.MatchCount; i++) { matcher[i] = getCharFromInt(HexParser.GetNumber(matcher[i, 1])); } text = matcher.ToString(); } if (matcher.IsMatch(text, "'`o_' /(['0-7_']+)")) { for (var i = 0; i < matcher.MatchCount; i++) { matcher[i] = getCharFromInt(OctParser.GetNumber(matcher[i, 1])); } text = matcher.ToString(); } if (matcher.IsMatch(text, "'`b_' /(['01_']+)")) { for (var i = 0; i < matcher.MatchCount; i++) { matcher[i] = getCharFromInt(BinParser.GetNumber(matcher[i, 1])); } text = matcher.ToString(); } if (matcher.IsMatch(text, "'`' /(['0-9_']+)")) { for (var i = 0; i < matcher.MatchCount; i++) { matcher[i] = getCharFromInt(matcher[i, 1].Replace("_", "").ToInt()); } text = matcher.ToString(); } return(text); }
private void ReceiveCallback(IAsyncResult ar) { try { if (!this.closing) { int n = this.tcpsocket.EndReceive(ar); this.ping.ResetConnState(); if (n > 0) { this.rcvbuf.AddDataLen(n); while (this.rcvbuf.count > TcpBuffer.PCK_MIN_SIZE) { BinParser parser = new BinParser(this.rcvbuf.buf, this.rcvbuf.offset); int head = parser.Int(); if (head != TcpBuffer.PCK_HEADER) { this.rcvbuf.Clear(); break; } int length = (int)parser.Short(); if (length > this.rcvbuf.count) { break; } byte[] tmpbuf = new byte[length]; Buffer.BlockCopy(this.rcvbuf.buf, this.rcvbuf.offset + TcpBuffer.PCK_MIN_SIZE, tmpbuf, 0, length); this.rcvbuf.DeleteData(length + TcpBuffer.PCK_MIN_SIZE); this.OnReceive(tmpbuf); // just put in a msg queue, not whole logic! } this.rcvbuf.Reset(); this.PostReceive(); // the reason why you need a msg queue! } else { this.OnError(errors.New("empty data!!")); this.Close(); } } } catch (Exception e) { this.OnError(errors.New(e.Message)); } }