private void UnexpectedResponse(Response.Types responseType, Request.Types requestType) { string ex = string.Format( "Unexpected {0} response for request {1}.", responseType, requestType ); throw new Exception(ex); }
private Response ReadResponse(NetworkStream stream) { BinaryReader r = new BinaryReader(stream); Response.Types responseType = (Response.Types)r.ReadByte(); int responseLength = IPAddress.NetworkToHostOrder(r.ReadInt32()); if (responseLength > MaxLength) { throw new Exception( "SendMessage got a response that exceeded max length"); } byte[] responseData = new byte[0]; if (responseLength > 0) { responseData = r.ReadBytes(responseLength); } return(new Response(responseType, responseData)); }
static void ParseString(string line) { Response.Types type = Response.ParseType(line[0]); line = line.Remove(0, 1); string source, response; source = response = ""; bool quote = false; bool part = false; for (int i = 0; i < line.Length; i++) { if (line[i] == '\"') { quote = !quote; continue; } if (!quote && line[i] == ':') { part = true; continue; } if (quote) { if (part) { response += line[i]; } else { source += line[i]; } } } responses.Add(new Response { source = source, response = response, type = type }); }