/** * Send first message handshake * */ public void OnConnected() { HttpHeader header = new HttpHeader(); header.headers[HttpHeader.PROTOCOL_KEY] = HttpHeader.PROTOCOL_INIT_VALUE; header.headers[HttpHeader.REMOTE_IP_KEY] = remote_host.Address.ToString(); //header.headers [HttpHeader.REMOTE_IP_KEY] = "128.179.143.241"; setListenIP (header); header.headers[HttpHeader.USER_AGENT_KEY] = HttpHeader.USER_AGENT_DEFAULT_VALUE; header.headers[HttpHeader.ACCEPT_KEY] = HttpHeader.G2ACCEPT_DEFAULT_VALUE; header.headers[HttpHeader.IS_HUB_KEY] = "False"; //header.headers [HttpHeader.IS_ULTRA_PEER_KEY] = "False"; header [HttpHeader.HUB_NEEDED_KEY] = "True"; setEncoding (header); string strMsg = header.ToString(); byte[] msg = System.Text.Encoding.ASCII.GetBytes(strMsg); bool byte_sent = tcp.Send(new ByteBuffer(msg)); }
/** * When the response of the hub is successful, we terminate the handshake * */ private void OnReply() { try { HttpHeader h = new HttpHeader(); h[HttpHeader.PROTOCOL_KEY] = "GNUTELLA/0.6 200 OK"; h[HttpHeader.CONTENT_TYPE_KEY] = HttpHeader.CONTENT_TYPE_G2_VALUE; h[HttpHeader.IS_HUB_KEY] = "False"; //h[HttpHeader.IS_ULTRA_PEER_KEY] = "False"; // /** TODO check if encoding is present **/ setEncoding(h); byte[] msg = System.Text.Encoding.ASCII.GetBytes(h.ToString()); bool byte_sent = tcp.Send(new ByteBuffer(msg)); } catch (ArgumentNullException ane) { throw new ArgumentNullException("GHandshakeOnReply() : {0}", ane.ToString()); } catch (SocketException se) { throw new NetException("GHandshakeOnReply() : " + se.ToString()); } catch (Exception e) { G2Log.Write("GHandshake ERROR OnReply() : " + e.ToString()); } }