Tutorial feedback

I’m trying SpiderMonkey in Ubuntu and I’m following your tutorial.

There seems to be two “problems” with it.


  1. Connection Filters:

    The ‘address’ of the client and ‘InetAddress.getLocalHost()’ are different.

    Because ‘address=/127.0.0.0’ and the ‘InetAddress.getLocalHost() = Ubuntu/127.0.0.0’

    This was very easy to overcome.

    I didn’t knew this, it’s a first for me and so I thought you should know.


  2. Discover Hosts:

    In here my code can’t find any hosts and I checked and double-checked if the server was online.

    Even tried to use your code and nothing.

    I think this problem is related with the first one.



    That’s it, hope it help

    I’ll give you more feedback, when necessary.

Hey there! Thanks for giving SpiderMonkey a try!



About 1) and 2); I’ll definitely look into these problems, have not heard about them yet. I’ll keep you posted on the status!

Okay, checked em both out, but I have some questions.


  1. Okay, I’m getting this too:

    /127.0.0.1 // Servers view on the client’s address

    iFurry.local/192.168.1.7 // Client’s InetAddress.getLocalHost()



    (Yes I call my iMac iFurry :wink:)



    But I do not see a problem, what would you like to see changed?:slight_smile:


  2. Since 1) also occurs for me, and discover hosts is also working for me, it seems unrelated. I’m going to need some more info on this matter :slight_smile: Could you provide me with some code that illustrates the problem(s) for you?



    Thanks for using SpiderMonkey :slight_smile:
1 Like

I think the terminology here is kind of confusing. You might try to find a better explanation for “Servers view on the client’s address”



Perhaps something like:

“Server recognizes you as: 127.0.0.1”

“Your IP address is: 192.168.1.7”

“Your shoe size is: 12”

2 Likes

Yeah Skye, you’re right, but do you mean this for my post or for SpiderMonkey itself?



As for my post, what you said is correct hehe. In other words:



Passed to the connection filters: /127.0.0.1



Which may be more to what @abarroso needs.

@sbook you were right, I wasn’t precise with what I was talking about. I’ll try to do it now.



@Levia as you requested, I remade the steps I did, so that the erros would appear again and that even remembered me of something else



In the https://wiki.jmonkeyengine.org/legacy/doku.php/spidermonkey:tutorial:connection on “Connecting Filters” you have:

[java]public class MyConnectorFilter implements ConnectorFilter {

public String filterConnector(InetSocketAddress address) {

if (address == InetAddress.getLocalHost()) return “I don’t like locals!”;

return null;

}

}[/java]

And there’s an error that for me it was no problem of detecting and amending. “address” and “InetAddress.getLocalHost()” aren’t of the same type. Don’t you have to add “address.getAddress()” instead?



About my first post, here are some more details for the point number 1)

MyServer Code:showing only the important part
[java] System.out.println("Starting server...");
myServer = new Server(4040, 5050);
MyConnectionFilter filter = new MyConnectionFilter();
myServer.addConnectorFilter(filter);
myServer.start();
System.out.println("Server started!");
System.out.println("waiting for clients...");
[/java]
MyClient Code:showing only the important part
[java] System.out.println("Connecting client...");
myClient = new Client("localhost", 4040, 5050);
myClient.start();
System.out.println("Client Connected!");[/java]
MyConnectionFilter Code:showing only the important part
[java]public String filterConnector(InetSocketAddress address) {
System.out.println("Incoming address : "+address.getAddress());
System.out.println("Localhost address : "+InetAddress.getLocalHost());
if (address.getAddress() == InetAddress.getLocalHost()) return "I don't like locals!";[/java]

MyServer Output:
[java]/*Starting server...
05-Oct-2010 14:22:13 com.jme3.network.connection.TCPConnection bind
INFO: [Server#1][TCP] Bound to 0.0.0.0/0.0.0.0:4040
05-Oct-2010 14:22:13 com.jme3.network.connection.UDPConnection bind
INFO: [Server#1][UDP] Bound to 0.0.0.0/0.0.0.0:5050
05-Oct-2010 14:22:13 com.jme3.network.connection.Server start
INFO: [Server#1][???] Started server.
Server started!
waiting for clients...
Incoming address : /127.0.0.1
Localhost address : ubuntu/127.0.1.1
05-Oct-2010 14:22:17 com.jme3.network.connection.TCPConnection accept
INFO: [Server#1][TCP] A client connected with address /127.0.0.1*/[/java]
For the point number 2)
I'm using your code from the tutorial too.

MyServer Code:showing only the important part
[java] System.out.println("Starting server...");
myServer = new Server(4040, 5050);
MyConnectionFilter filter = new MyConnectionFilter();
myServer.addConnectorFilter(filter);
myServer.start();
System.out.println("Server started with tcpPort : 4040 , udpPort : 5050");
System.out.println("waiting for clients...");[/java]
MyClient Code:showing only the important part
[java] System.out.println("Connecting client...");
Client client = new Client();
long start = System.currentTimeMillis();
List foundHosts = client.discoverHosts(5050, 5000);
System.out.println("Stopped looking for hosts after "+(System.currentTimeMillis() - start)+"ms");
for (InetAddress host : foundHosts) {
client.connect(host.getCanonicalHostName(), 4040, 5050);
}
System.out.println("Number of host found : "+foundHosts.size());
System.out.println("List of host found : "+foundHosts.toString());
myClient.start();
System.out.println("Client Connected!");
[/java]

MyServer output:
[java]/*Starting server...
05-Oct-2010 14:40:32 com.jme3.network.connection.TCPConnection bind
INFO: [Server#1][TCP] Bound to 0.0.0.0/0.0.0.0:4040
05-Oct-2010 14:40:32 com.jme3.network.connection.UDPConnection bind
INFO: [Server#1][UDP] Bound to 0.0.0.0/0.0.0.0:5050
05-Oct-2010 14:40:32 com.jme3.network.connection.Server start
INFO: [Server#1][???] Started server.
Server started with tcpPort : 4040 , udpPort : 5050
waiting for clients...*/[/java]

MyClient output:
[java]/*Connecting client...
Stopped looking for hosts after 5065ms
Number of host found : 0
List of host found : []
Exception in thread "main" java.lang.NullPointerException
at networking.MyClient.main(MyClient.java:39)
Java Result: 1*/[/java]

This should be more cleared right?

I hope that I'm not complaining too much.
Are just details.
But I would like to know what I'm doing wrong at the point 2)

(lol @ iFury)
3 Likes
Levia said:
Yeah Skye, you're right, but do you mean this for my post or for SpiderMonkey itself?

As for my post, what you said is correct hehe. In other words:

Passed to the connection filters: /127.0.0.1

Which may be more to what @abarroso needs.


Well, if that wording is in SpiderMonkey then yes :)

@abarroso That is a an extremely well formed post, awesome!

For point number 1):

I’ve tested the connector filters, and it turns out you’re right. I changed it to



public class MyConnectorFilter implements ConnectorFilter {

public String filterConnector(InetSocketAddress address) {

if (address.isLoopbackAddress()) return “I don’t like locals!”;

return null;

}

}



which yields the expected result.



About point 2)

Thank you very much for supplying the code segments. I’ve tested them and they are working fine for me :frowning: I’m seeing some improper use of variables, that might be the problem, if that’s really what’s going on in your application. For example you posted:



System.out.println(“Connecting client…”);

Client client = new Client();

long start = System.currentTimeMillis();

List foundHosts = client.discoverHosts(5050, 5000);

System.out.println("Stopped looking for hosts after "+(System.currentTimeMillis() - start)+“ms”);

for (InetAddress host : foundHosts) {

client.connect(host.getCanonicalHostName(), 4040, 5050);

}

System.out.println("Number of host found : "+foundHosts.size());

System.out.println("List of host found : "+foundHosts.toString());

myClient.start();

System.out.println(“Client Connected!”);



Where myClient.start(); should be client.start()?

I will give you want you want.

But you will have to wait a while.



See you soon