Gnutella Forums

Gnutella Forums (https://www.gnutellaforums.com/)
-   Connection Problems (https://www.gnutellaforums.com/connection-problems/)
-   -   connection issue (https://www.gnutellaforums.com/connection-problems/19419-connection-issue.html)

mjin March 14th, 2003 02:14 PM

connection issue
 
I am testing initial connection to Gnucleus 1.8.4.0 with my limewire Client.
I'v notice I must send "GNUTELLA/0.6 200 OK" very quick, right after the 200 ok response. other wise I can't set up the connection to Gnucleus.
First I was wondering it is timer issue, after I check the source code(CGnuNode::OnReceive) and change the timeout value, it is the same.

CAsyncSocket::OnReceive didn't get invoked at all. Can anybody help me on it?

private void connectToServer() {
try {
socket = new Socket(InetAddress.getLocalHost(), SERVER_PORT);
row_in = socket.getInputStream();

in = new BufferedReader(new InputStreamReader (socket.getInputStream()));

out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));

} catch(IOException e) {
System.out.println("CLIENT: Cannot connect to server");
System.exit(-1);
}

try {
sendString("GNUTELLA CONNECT/0.6");
sendString("User-Agent: limewire");
sendString("X-Ultrapeer: False");
sendString("X-Query-Routing: 0.1");
sendString("Uptime: 1D 00H 00M");
sendString("Remote-IP: 192.168.0.4:7000\r\n");
String response = in.readLine();

System.out.println("read = " + response);

//if I send response here, it works
//sendString("GNUTELLA/0.6 200 OK\r\n");

while( response != null ){
response = in.readLine();
System.out.println("read = " + response);
}

//if i put it here, it doesn't work
sendString("GNUTELLA/0.6 200 OK\r\n");


....
...

private void sendString(String s) throws IOException {
out.println(s);
out.flush();
}

trap_jaw March 14th, 2003 03:13 PM

Your headers are not HTTP compliant.

java's println(String) functions just append a newline character '\n' to the string. The correct way to terminate a HTTP header line is appending a carriage return and than a newline to the line: '\r\n'.

The while loop is not going to work properly either. The correct while loop should be:

while (!response.equals("")) {
if (response == null) {
throw new IOException("reading null indicates an error");
}
...
}


Java's readLine functions block until they read a non-null string. If readLine() cannot read a string it throws an IOException (either because the connection failed or because you specified a read timeout by setting Socket.soTimeout(int != 0).

I don't know the gnucleus sources but that was not the problem keeping you from connecting. The code opening the socket appears to be correct so Gnucleus should at least notice the connection attempt.

If you have any further questions feel free to mail me ( gregorio at gmx.li ) or subscribe to the limewire devel mailinglists at www.limewire.org ( dev@core.limewire.org is the place to go for questions like this).


All times are GMT -7. The time now is 05:40 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 ©2011, Crawlability, Inc.

Copyright © 2020 Gnutella Forums.
All Rights Reserved.