/** * Read the response header to see if there are packets * sometimes , browsable packet is present but servent has disactivated for G2 network * (shaeraza) * return true if servent will stream g2packets * return false if not (html code listing neighbours / or nothing) * */ public bool ReadResponseHeader(TCPConnection con) { ByteBuffer resp = con.Read(); if (resp == null) { return(false); } string text = BinaryUtils.getStringFromBytes(resp.Bytes, (int)resp.DataOffset); string sequence = HttpHeader.nl + HttpHeader.nl; string[] splitter = { sequence }; string[] header = text.Split(splitter, StringSplitOptions.RemoveEmptyEntries); if (header.Length < 2) { return(false); } // check if the http header is OK i.e. will the servent stream g2 packets ? if (!ParseBrowsingResponse(header[0])) { return(false); } // remove the http header part from the buffer int dataOffset = text.IndexOf(sequence) + sequence.Length; resp.Dequeue(dataOffset); // put available data into the reader reader = new G2PacketReader(this.Peer); reader.Read(resp); return(true); }
/** * Handles the response of the remote host, * comes after OnConnected * */ public Boolean OnResponse() { ByteBuffer readBuffer = tcp.Read(); if (readBuffer == null) { return(false); } int byte_received = readBuffer.DataOffset; if (byte_received <= 0) { throw new NetException("GHandshake OnResponse : no responses "); } string msg = System.Text.Encoding.ASCII.GetString(readBuffer.Bytes, 0, readBuffer.DataOffset); return(handleReply(msg)); }