Hi
I think in jme3test.network.TestHostDiscovery doesn’t work line
[java]
List hosts = client.discoverHosts(5110, 5000);
[/java]
doesn’t work.
Here is exception
[java]
Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at networking.TestHostDiscovery.main(TestHostDiscovery.java:55)
[/java]
Oh, I’m sorry!!!
jme3test.network.TestHostDiscovery doesn’t work, but the method client.discoverHosts() works on different computers. May be it doesn’t look for “localhost”???
If you have a firewall on your PC, it might be blocking outbound broadcast packets, so the List will be empty.
Thank you. I’ve totally forgot about firewall.
The same test
[java]
import com.jme3.network.connection.Client;
import com.jme3.network.connection.Server;
import java.io.IOException;
import java.net.InetAddress;
import java.util.List;
public class TestHostDiscovery {
public static void main(String[] args) throws IOException, InterruptedException{
Server server = new Server(5110, 5110);
server.start();
Client client = new Client();
client.start();
List hosts = client.discoverHosts(5110, 5000);
for (InetAddress host : hosts){
System.out.println("Found host: " + host);
System.out.println("Reachable? " + host.isReachable(5000));
}
System.out.println("Connecting to: "+ hosts.get(0));
client.connect(hosts.get(0).getCanonicalHostName(), 5110, 5110);
Thread.sleep(500);
System.out.println(server.getConnectors().size());// Why an output is 0?
}
}
[/java]
Why an output is 0?
I assume it actually found a host now?
Lets look to following codes
[java]
import java.net.InetAddress;
import java.util.List;
import com.jme3.network.connection.Client;
import com.jme3.network.connection.Server;
public class TestSearchConnection{
public static void main(String[] args) throws Exception{
Server server = new Server(2911, 2911);
server.start();
Client client = new Client();
client.start();
List hosts = client.discoverHosts(2911, 5000);
for (InetAddress host : hosts){
System.out.println("Found host: " + host); // Found host: /192.168.1.3
System.out.println("Reachable? " + host.isReachable(5000)); // Reachable? true
}
System.out.println("Connecting to: "+ hosts.get(0));
client.connect(hosts.get(0).getCanonicalHostName(), 2911, 2911); // Connecting to: /192.168.1.3
Thread.sleep(1000);
System.out.println(server.getConnectors().size()); // 0
System.out.println(server.getTCPConnectors().size()); // 1
System.out.println(server.getUDPConnectors().size()); // 0
}
}
[/java]
and this
[java]
import com.jme3.network.connection.Client;
import com.jme3.network.connection.Server;
public class TestAddressConnection{
public static void main(String args[]) throws Exception{
Server server = new Server(2911, 2911);
server.start();
Client client = new Client(“127.0.0.1”, 2911, 2911);
client.start();
Thread.sleep(1000);
System.out.println(server.getConnectors().size()); // 1
System.out.println(server.getTCPConnectors().size()); // 1
System.out.println(server.getUDPConnectors().size()); // 1
}
}
[/java]
In the first i had output
[java]
…
Found host: /192.168.1.3
Reachable? true
Connecting to: /192.168.1.3
…
0
1
0
[/java]
Means that if I am able to send message only by TCP connection.
And in the second
[java]
…
1
1
1
[/java]
I can use TCP, UDP and combined connection. I thought the first and the second ought to be the same thing.
Am I doing something wrong?
Something strange is happening…
[java]
import com.jme3.network.connection.Client;
import com.jme3.network.connection.Server;
public class TestAddressConnection{
public static void main(String args[]) throws Exception{
Server server = new Server(2911, 2911);
server.start();
Client client = new Client(“192.168.1.3”, 2911, 2911);
client.start();
Thread.sleep(1000);
System.out.println(server.getConnectors().size());
System.out.println(server.getTCPConnectors().size());
System.out.println(server.getUDPConnectors().size());
}
}
[/java]
The output is
[java]
1
1
1
[/java]
Now I try to pass an address in constructor.
[java]
import java.net.InetAddress;
import java.util.List;
import com.jme3.network.connection.Client;
import com.jme3.network.connection.Server;
public class TestSearchConnection{
public static void main(String[] args) throws Exception{
Server server = new Server(2911, 2911);
server.start();
Client client = new Client(); //Do not start
List hosts = client.discoverHosts(2911, 5000);
Client cli = new Client(hosts.get(0).getHostAddress(), 2911, 2911);
cli.start();
Thread.sleep(1000);
System.out.println(hosts.get(0).getHostAddress());
System.out.println(server.getConnectors().size());
System.out.println(server.getTCPConnectors().size());
System.out.println(server.getUDPConnectors().size());
}
}
[/java]
Output
[java]
192.168.1.3
0
1
0
[/java]