Captive Imagination
September 10, 2010, 04:02:28 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: jSeamless 1.0 Beta 7 is Available http://www.jseamless.org
 
   Home   Help Search Calendar Login Register  
Pages: 1 2 3 [All]   Go Down
  Print  
Author Topic: Listing Servers  (Read 5614 times)
0 Members and 1 Guest are viewing this topic.
nymon
Newbie
*
Offline Offline

Posts: 23


View Profile
« on: November 07, 2006, 01:36:32 PM »

Hey Darkfrog,

I'm ready to roll JGN into a game, but was thinking some stuff out before hand. What is the best way to search for and list JGN servers which are running on a LAN? I was reading an old post about ServerRegister but couldn't really follow it, and I couldn't find it in the source.

Is there a built in way of doing this?
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #1 on: November 07, 2006, 02:06:33 PM »

There was in 1.0 but it didn't make it into 2.0.  I really need to go back and add that feature.  The ServerRegistry was essentially just a system that would allow you to register MessageServers with it based on a "group name" and so someone could hit that centralized server and give a group name (say for the specific game they want to play) and it would return a list of all the available servers back.

It's a pretty simple system, but if that's something you're ready to start using I'll make it a priority to get it in.  I will be needing it for another game eventually but had sort of put it on the back-burner until I need it.
Logged
nymon
Newbie
*
Offline Offline

Posts: 23


View Profile
« Reply #2 on: November 07, 2006, 05:50:28 PM »

I hate to rush but it is something I would love to have. It's not essential for me immediately, but the sooner the better. My plan was to have the networking in place within 2 weeks, assuming nothing holding me back. This is, in all reality, for convenience and there is no reason I could not proceed without it.

What I understand about what you just explained, the user would need to know the address of the system hosting the ServerRegistry in order to query it. Are there any unwritten (or written) rules against a port scan of the computers in a LAN so the user need not know anything, its just magic?
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #3 on: November 07, 2006, 06:19:03 PM »

Well, that's always another route to go.  You wouldn't want to do a portscan per se, but you might have a specific connection port that is required to be open for your game and simply scan the subnet trying to establish a connection.  I believe that's how LAN games typically work.  As for something like BF2 they have a registry that you contact for a list. A server has to "check-in" with the registry every so often or they get dropped from the list.

If you decide to go the LAN style route (which obviously wouldn't work for internet games) I would be happy to help you get that set up.  It should be extremely straight-forward with JGN without any additional features.
Logged
nymon
Newbie
*
Offline Offline

Posts: 23


View Profile
« Reply #4 on: November 07, 2006, 06:46:42 PM »

At this point I think keeping down to a LAN would be acceptable.
Quote
have a specific connection port that is required to be open for your game and simply scan the subnet trying to establish a connection
Exactly what I had in mind!

Thanks for offering to help. Is there a specific setup which I should follow that would cater to this, or is all the same? I've run all the tests and examples you've provided and If the general setup is not different than what I can find there I'll go ahead see what I can flesh out.

The subnet scan is something I'll have to research, unless soliciting your help is all the research I need.

Also, do you recommend your last release or pulling the cvs at this point?
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #5 on: November 07, 2006, 08:19:50 PM »

The subversion source is pretty stable right now so feel free.  I always give plenty of notice if I'm going to create any instabilities in the repository and create a release that can be fallen back on if problems do occur as a result.

You can rely pretty closely with the examples, that should be fine.

As for the subnet scan you should just be able to grab your own local IP address and rip off the last number and start a scan from 1 - 255 and try to connect.
Logged
nymon
Newbie
*
Offline Offline

Posts: 23


View Profile
« Reply #6 on: November 07, 2006, 10:16:32 PM »

Thanks for the pointer. I'll keep you posted of any deep findings. Smiley
Logged
nymon
Newbie
*
Offline Offline

Posts: 23


View Profile
« Reply #7 on: November 08, 2006, 10:26:21 AM »

Now when doing the scan, do I have to attempt a TCP connection to each address, or can I rapid fire UDP's and wait for responses? The fastest way is what I'm looking for.
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #8 on: November 08, 2006, 10:43:34 AM »

That's actually a really good point.  I might add a feature to JGN to have something like:

Code:
boolean JGN.isServerAtAddress(InetSocketAddress, Type, int timeout)

Type would represent UDP or TCP.

I started working on the ServerRegistry and it will be far superior to the original one and much more extensible.
Logged
nymon
Newbie
*
Offline Offline

Posts: 23


View Profile
« Reply #9 on: November 08, 2006, 11:11:25 AM »

What is a reasonable timeout when waiting for a response? Of course it depends on the network, but for a regular LAN is something like 10ms too short or too long?
Logged
nymon
Newbie
*
Offline Offline

Posts: 23


View Profile
« Reply #10 on: November 08, 2006, 11:13:26 AM »

Also, do I have to wait for the timeout before checking another address or can I send as fast as I can and just catch the responses as they come?
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #11 on: November 08, 2006, 12:55:26 PM »

Good point....I will consider this much more as I think I could come up with an NIO approach to that where you can cycle through all the addresses you want to hit and give it a timeout (probably 1 second) and get a reference that you can check back with to see if it has timed out or gotten a valid response.

If you're willing to wait a couple days on this one I'll get something into the core of JGN to add support for TCP and UDP.
Logged
nymon
Newbie
*
Offline Offline

Posts: 23


View Profile
« Reply #12 on: November 08, 2006, 01:18:02 PM »

Yeah I'll wait, Thanks
Logged
kine
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« Reply #13 on: September 15, 2008, 05:18:18 AM »

Hi All !  Smiley

Darkfrog, did you finally implement smt like boolean JGN.isServerAtAddress(InetSocketAddress, Type, int timeout) ?

Can you explain me a bit what instructions are needed to scan a lan, at least how to retrieve lan adresses ?

Tanks in advance  Cheesy

Kine
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #14 on: September 15, 2008, 07:19:31 AM »

No, I never got around to this, but if you're interested in writing it and contributing back that would be greatly appreciated. Wink

The easiest way is to gather the machine's IP addresses (exclude 127.0.0.1 obviously) and then replace the last digit with your scan 1 - 255.  If you do this non-blocking (as opposed to scan and wait) you could simultaneously send requests to all 254 (exclude the local IP) addresses and give a certain amount of time for them to respond.

However, you could also look into multicast and though JGN doesn't have built-in support for this for this scenario it would really be powerful.
Logged
nymon
Newbie
*
Offline Offline

Posts: 23


View Profile
« Reply #15 on: September 15, 2008, 02:28:24 PM »

Two years later and we've come right back around to the same point!  Grin
I would like to have this as well (again). So, I'm willing to help you out kine with ideas and such if I can.
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #16 on: September 15, 2008, 04:42:51 PM »

I'm happy to help with concepts and such, but code-writing time is strained for me. Smiley
Logged
kine
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« Reply #17 on: September 16, 2008, 11:24:57 AM »

Hi :-)

here is a sample code to scan ips and opened ports
when I'll have time I'll make a multithreaded more efficient scan and why not even contribute to JGN :-)
it takes approx 3 seconds to scan 255 ips ( max delay 10ms)

Code:
package networkingTemp;

import java.io.IOException;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class KineIpScanner {

private InetAddress serverReliable, serverFast, clientReliable, clientFast;

KineIpScanner() {

for (int i = 0; i < 256; i++) {

try {
serverReliable = InetAddress.getByName("192.168.1." + i);
boolean f = serverReliable.isReachable(10);
if (f) {
System.out.println(serverReliable.getHostName());
JOptionPane.showMessageDialog(new JFrame(), "found "
+ serverReliable.getHostName() + "at address :"
+ serverReliable.getHostAddress() + "",
"Warning !!!", 1);

PortScan();
}
} catch (IOException e) {
System.out.println("Client initialization failed");
}
}

System.out.println("finished");
}

private void PortScan() {

for (int i = 5000; i < 10000; i++) {
try {

Socket s = new Socket(serverReliable, i);
JOptionPane.showMessageDialog(new JFrame(),
"Socket Created on " + serverReliable.getHostName()
+ " at port " + i + "", "Warning !!!", 1);
} catch (UnknownHostException unhe) {
JOptionPane.showMessageDialog(new JFrame(), "Problem Finding "
+ serverReliable.getHostName() + "", "Warning !!!", 1);
} catch (ConnectException ce) {

} catch (IOException ie) {
JOptionPane.showMessageDialog(new JFrame(),
"IOException Occured\n" + ie + "", "Warning !!!", 1);
}
}
}

public static void main(String[] args) {
KineIpScanner app = new KineIpScanner();

}

Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #18 on: September 16, 2008, 12:51:42 PM »

You could use JGN's "ping" functionality to try to ping the servers and since JGN is entirely asynchronous anyway you'd just have to wait for results.
Logged
nymon
Newbie
*
Offline Offline

Posts: 23


View Profile
« Reply #19 on: September 16, 2008, 01:10:10 PM »

I think instead of a port scan (which may be considered a little hostile) you should just specify a particular port you are looking for. In most cases you will only ever be looking for one specific port; is this right Darkfrog?

Good start though, father than I got.
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #20 on: September 16, 2008, 05:44:38 PM »

That's correct....in fact, that's what pinging does is hit a specific port.
Logged
kine
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« Reply #21 on: September 17, 2008, 06:28:39 AM »

Hi !  Tongue

Sorry for this stupid question, but I can't find a correct way to use ping ...

Here is how I can manage to do it:
boolean found = (new TCPMessageServer(new InetSocketAddress(foundIP, bolidzport, 1000)) != null); for example, but I don't know howto use JGN ping method ...

Can you show me the way to use JGN's ping method  DarkFrog ? Smiley

Kine  Cheesy
      
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #22 on: September 17, 2008, 07:28:01 AM »

Ugh, I just realized that you have to have an existing connection....we should write something that allows you to check to see if the port is open before anything else.
Logged
kine
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« Reply #23 on: September 19, 2008, 05:32:02 AM »

I think I'll wait a bit before sending my code ... but I'll do so in a month or two...

         I'm not experienced enough with JGN & java . For the moment I prefer to focus on my game and make a "KineDirtyJava  Kiss" IP scan+opened ports scan + JGN connection scan, and I'll clean it later when I'll be aware of all these multithreading and exception stuffs.

See you :-)

Kine
Logged
kine
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« Reply #24 on: September 19, 2008, 09:19:46 AM »

I guess to use a multi threaded JGN server scan we'd have to use several clients ?
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #25 on: September 19, 2008, 10:44:12 AM »

Yeah, you'd probably want to have your local MessageServer attempt to connect to a specified port on each address in that IP range and store the MessageClients you get back to see which ones end up connecting and which ones fail.  The port you attempt to connect to could be specifically for game information so you can get real-time data about that game and then disconnect when you're done.
Logged
kine
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« Reply #26 on: September 20, 2008, 10:28:53 AM »

Well, here is what I've done ...

I'm not very good at coding thread, exceptions  Sad ( I guess I'll get better btw feel free to give me advices  )  etc so correct & don't bother,  anyway it works quite safely, and under linux also. It's multithreaded. ( I included LinuxInetAdress again() )

nevertheless, I Hope this helps  Wink

Kine

Code:
package menu.networkingUtilities;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.HashSet;
import java.util.Set;

import networking.LinuxInetAddress;

import com.captiveimagination.jgn.JGN;
import com.captiveimagination.jgn.MessageServer;
import com.captiveimagination.jgn.TCPMessageServer;

public class LanScan {

int actualTempPort = 30000;

private boolean wait = true;
static MessageServer server;

Set<Integer> ports;
Set<SpecifiedIPScan> portScans = new HashSet<SpecifiedIPScan>();

final Set<InetSocketAddress> JGNServers = new HashSet<InetSocketAddress>();

LanScan(String subNetMask, int delay, Set<Integer> ports) {

// Set<InetAddress> IPAdresses = new HashSet<InetAddress>();
// try {
// IPAdresses.add(InetAddress.getByName("192.168.1.201"));
// } catch (IOException e) {
// System.out.println("Client initialization failed");
// }

this.ports = ports;
Set<InetAddress> IPAdresses = findIPs(subNetMask, delay);

}

private Set<InetAddress> findIPs(String subNetMask, int delay) {

InetAddress scanIPAddress;
System.out.println("Start scanning for lan computers ...");
Set<InetAddress> IPAddresses = new HashSet<InetAddress>();

for (int i = 0; i < 256; i++) {

try {
scanIPAddress = InetAddress.getByName(subNetMask + i);
boolean f = scanIPAddress.isReachable(delay);
if (f) {

System.out.println("found a computer on the lan !! : "
+ scanIPAddress.getHostName() + " ("
+ scanIPAddress.getHostAddress() + ")");
IPAddresses.add(scanIPAddress);

SpecifiedIPScan portScan = new SpecifiedIPScan(scanIPAddress, ports,
JGNServers);

portScans.add(portScan);

}
} catch (IOException e) {
System.out
.println("problem retreiving IP lan adresses, exiting");
System.exit(0);
}
}

while (wait) {
int threadFinished = 0;
try {

for (SpecifiedIPScan portScan : portScans) {

for (Thread thread : portScan.threads) {

if (thread.isAlive()) {
threadFinished++;
}
}

}

if (threadFinished == 0)
wait = false;

Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
}
}
System.out.println("finished !!!!!!!!");
System.out.println("So ...........; there is " + JGNServers.size()
+ "  JGN servers ");
for (InetSocketAddress inetAddress : JGNServers) {
System.out.println("---->JGN Server : " + inetAddress.getHostName()
+ "(" + inetAddress.getAddress() + "):"
+ inetAddress.getPort());

}

try {
server.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return IPAddresses;

}

private static void createAServer() {

try {
server = new TCPMessageServer(new InetSocketAddress(InetAddress
.getByName(LinuxInetAddress.getLocalHost()), 15000));

NetworkFindingMessageServer tms = new NetworkFindingMessageServer(1);
// We add it to this server as a message listener
server.addMessageListener(tms);
// We add it to this server as a connection listener
server.addConnectionListener(tms);
// If you have an update thread of your own this is not necessary as
// you can simply
// call server.update(), but this is a convenience method for
// multithreading.
JGN.createThread(server).start();

System.out.println("debugging server is alive ?! : "
+ server.isAlive());

} catch (IOException e) {
System.out.println("debugging server is alive ?! : no");

}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
System.out.println("debugging server is alive ?! : no");

}
}

public static void main(String[] args) {
Set<Integer> ports = new HashSet<Integer>();


//////////sample debugging ports ....



ports.add(15000);

ports.add(10148);

ports.add(20148);

String tempSubNetwork = "";

try {
tempSubNetwork = LinuxInetAddress.getLocalHost();
} catch (UnknownHostException e) {

}

int i = tempSubNetwork.lastIndexOf(".");
String subNetwork = tempSubNetwork.substring(0, i + 1);
System.out.print("Subnetwork : " + subNetwork + " ports tested : ");
for (int port : ports) {
System.out.print(port + ",");
}

createAServer();// <------- create a temporary server for debugging;

LanScan app = new LanScan(subNetwork,
50, ports);

}

Code:
package menu.networkingUtilities;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;

import com.captiveimagination.jgn.JGN;
import com.captiveimagination.jgn.MessageClient;
import com.captiveimagination.jgn.MessageServer;
import com.captiveimagination.jgn.TCPMessageServer;
import com.captiveimagination.jgn.event.ConnectionListener;
import com.captiveimagination.jgn.event.MessageListener;
import com.captiveimagination.jgn.message.Message;
import com.captiveimagination.jgn.ping.Ping;
import com.captiveimagination.jgn.test.basic.BasicMessage;
import com.captiveimagination.jgn.test.basic.TestMessageServer;

/**
 * @author Matthew D. Hicks
 */
public class NetworkFindingMessageServer implements MessageListener, ConnectionListener {
private int id;

public NetworkFindingMessageServer(int id) {
this.id = id;
}


public void messageCertified(Message message) {
}

public void messageFailed(Message message) {
}

public void messageReceived(Message message) {
}

public void messageSent(Message message) {
}

public void connected(MessageClient client) {
// System.out.println("Connected(" + id + "): " + ((InetSocketAddress)client.getAddress()).getPort());
}

public void disconnected(MessageClient client) {
// System.out.println("Disconnected(" + id + "): " + ((InetSocketAddress)client.getAddress()).getPort());
}

public void negotiationComplete(MessageClient client) {
}

public void kicked(MessageClient client, String reason) {
}
}

Code:
package menu.networkingUtilities;

import java.io.IOException;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Random;
import java.util.Set;

import javax.net.ServerSocketFactory;

import networking.LinuxInetAddress;

import com.captiveimagination.jgn.JGN;
import com.captiveimagination.jgn.MessageClient;
import com.captiveimagination.jgn.MessageServer;
import com.captiveimagination.jgn.TCPMessageServer;

public class SpecifiedIPScan {

int tempPort;
boolean connected = false;

ArrayList<Thread> threads = new ArrayList<Thread>();

SpecifiedIPScan(final InetAddress inetAddress, Set<Integer> ports,
final Set<InetSocketAddress> JGNServers) {

for (final int port : ports) {

Thread portScanThread = new Thread(new Runnable() {
public void run() {

SpecifiedIPScan portScan = new SpecifiedIPScan(new InetSocketAddress(
inetAddress, port), JGNServers, getAPort());

}
});

portScanThread.start();
threads.add(portScanThread);

}
}

private int getAPort() {

int numberOfPortsTried = 0;
boolean gotAPort = false;
int actualTempPort = 30000;
Random generator;
generator = new Random();

while (!gotAPort && (numberOfPortsTried < 100)) {
numberOfPortsTried++;

actualTempPort = 30000 + generator.nextInt(30000);

try {
ServerSocket s = ServerSocketFactory.getDefault()
.createServerSocket(actualTempPort);
s.close();
gotAPort = true;
return actualTempPort;
} catch (Throwable e1) {

}

}

System.out
.println("tried more than 99 ports to create a temporary client for testing. problem ... exiting ");
System.exit(0);
return 0;

}

SpecifiedIPScan(InetSocketAddress inetSocketAddress,
Set<InetSocketAddress> JGNServers, int tempPort) {

this.tempPort = tempPort;

if (checkIfThePortIsOpened(inetSocketAddress)) {

checkJGNServer(inetSocketAddress);

if (connected) {
System.out.println("JGN server found at :"
+ inetSocketAddress.getAddress() + " port:"
+ inetSocketAddress.getPort());

JGNServers.add(inetSocketAddress);
}
}
}

private boolean checkIfThePortIsOpened(InetSocketAddress inetSocketAddress) {
try {

// Socket s = new Socket(inetSocketAddress.getAddress(),
// inetSocketAddress.getPort());

Socket s = new Socket(InetAddress.getByName(inetSocketAddress
.getHostName()), inetSocketAddress.getPort());

System.out.println("port " + inetSocketAddress.getPort() + " on "
+ inetSocketAddress.getAddress().getHostName()
+ " open !!!");

/*
* JOptionPane.showMessageDialog(new JFrame(), "Socket Created on "
* + inetSocketAddress.getAddress().getHostName() + " at port " +
* inetSocketAddress.getPort() + "", "Warning !!!", 1);
*/
s.close();

return true;

} catch (UnknownHostException unhe) {
System.out.println("problem scanning "
+ inetSocketAddress.getAddress() + ":"
+ inetSocketAddress.getPort() + ", port skipped");

return false;
} catch (ConnectException ce) {
System.out.println("problem scanning "
+ inetSocketAddress.getAddress() + ":"
+ inetSocketAddress.getPort() + ", port skipped");

return false;
} catch (IOException ie) {
System.out.println("problem scanning "
+ inetSocketAddress.getAddress() + ":"
+ inetSocketAddress.getPort() + ", port skipped");

return false;
}

}

private void checkJGNServer(InetSocketAddress inetSocketAddress) {
boolean ok = false;
try {
MessageServer server2 = new TCPMessageServer(new InetSocketAddress(
InetAddress.getByName(LinuxInetAddress.getLocalHost()),
tempPort));
NetworkFindingMessageServer tms2 = new NetworkFindingMessageServer(
2);
server2.addMessageListener(tms2);
server2.addConnectionListener(tms2);
JGN.createThread(server2).start();

try {
Thread.sleep(1500);
} catch (InterruptedException e) {

}

MessageClient client = server2
.connect(new InetSocketAddress(inetSocketAddress
.getAddress(), inetSocketAddress.getPort()));

connected = true;

while (!client.isConnected()) {

try {
Thread.sleep(100);
} catch (InterruptedException e) {

}

}

client.disconnect();

while (client.isConnected()) {

try {
Thread.sleep(100);
} catch (InterruptedException e) {

}

}

server2.close();

while (server2.isAlive()) {

try {
Thread.sleep(100);
} catch (InterruptedException e) {

}

}

} catch (IOException ie) {
System.out.println("problem connecting a JGN server to  "
+ inetSocketAddress.getAddress() + ":"
+ inetSocketAddress.getPort() + ", port skipped");

}

}

public ArrayList<Thread> getThreads() {
return threads;
}

public void setThreads(ArrayList<Thread> threads) {
this.threads = threads;
}


Code:

package networking;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Enumeration;

public class LinuxInetAddress {

/**
* Returns an InetAddress representing the address of the localhost. Every
* attempt is made to find an address for this host that is not the loopback
* address. If no other address can be found, the loopback will be returned.
*
* @return InetAddress - the address of localhost
* @throws UnknownHostException
*             - if there is a problem determing the address
*/
public static String getLocalHost() throws UnknownHostException {

InetAddress localHost = InetAddress.getLocalHost();
if (!localHost.isLoopbackAddress()) {

return localHost.getHostAddress();
}
InetAddress[] addrs = getAllLocalUsingNetworkInterface();
for (int i = 0; i < addrs.length; i++) {
if (!addrs[i].isLoopbackAddress())
if (!addrs[i].isAnyLocalAddress())
if (!addrs[i].isLinkLocalAddress())

return addrs[i].getHostAddress();
}

return localHost.getHostAddress();

}

/**
* This method attempts to find all InetAddresses for this machine in a
* conventional way (via InetAddress). If only one address is found and it
* is the loopback, an attempt is made to determine the addresses for this
* machine using NetworkInterface.
*
* @return InetAddress[] - all addresses assigned to the local machine
* @throws UnknownHostException
*             - if there is a problem determining addresses
*/
public static InetAddress[] getAllLocal() throws UnknownHostException {

InetAddress[] iAddresses = InetAddress.getAllByName("127.0.0.1");
if (iAddresses.length != 1) {

return iAddresses;
}
if (!iAddresses[0].isLoopbackAddress()) {

return iAddresses;
}

return getAllLocalUsingNetworkInterface();

}

/**
* Utility method that delegates to the methods of NetworkInterface to
* determine addresses for this machine.
*
* @return InetAddress[] - all addresses found from the NetworkInterfaces
* @throws UnknownHostException
*             - if there is a problem determining addresses
*/
private static InetAddress[] getAllLocalUsingNetworkInterface()
throws UnknownHostException {

ArrayList addresses = new ArrayList();
Enumeration e = null;
try {
e = NetworkInterface.getNetworkInterfaces();
} catch (SocketException ex) {
throw new UnknownHostException("127.0.0.1");
}
while (e.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface) e.nextElement();
for (Enumeration e2 = ni.getInetAddresses(); e2.hasMoreElements();) {
addresses.add(e2.nextElement());
}
}
InetAddress[] iAddresses = new InetAddress[addresses.size()];
for (int i = 0; i < iAddresses.length; i++) {
iAddresses[i] = (InetAddress) addresses.get(i);
// System.out.println(iAddresses[i].getHostAddress());
// System.out.println(iAddresses[i].getHostName());
}

return iAddresses;

}
}
Logged
kine
Jr. Member
**
Offline Offline

Posts: 72


View Profile
« Reply #27 on: September 20, 2008, 10:33:59 AM »

oups it don't manage multi network interfaces ... anyway I guess it's not a big problem ...  Smiley
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #28 on: September 20, 2008, 12:50:26 PM »

Only took a brief read, but it looks good.  However, you probably want to have all the TCPMessageServers under a single thread rather than a thread for each one.  Threads are incredibly expensive to create and since JGN is entirely asynchronous you shouldn't have any problems having it all in a single thread.
Logged
Trussell
Jr. Member
**
Offline Offline

Posts: 52


View Profile
« Reply #29 on: June 22, 2009, 08:02:36 PM »

This doesn't work for me... does anybody know why? I am running my game on one computer and trying to see JGN servers with the LanScan code from my laptop, but it's not working. I see 0 servers. Any clues?
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #30 on: June 23, 2009, 07:22:02 AM »

Are you listening on TCP or UDP or both?

How have you bound your socket for listening?  You might try explicitly binding it to your machine's IP address and see if that changes anything.
Logged
Trussell
Jr. Member
**
Offline Offline

Posts: 52


View Profile
« Reply #31 on: June 24, 2009, 11:05:02 AM »

Are you listening on TCP or UDP or both?

How have you bound your socket for listening?  You might try explicitly binding it to your machine's IP address and see if that changes anything.

I am binding it like this:
Code:
serverReliable = new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), 9100);

Is that what you mean by binding it explicitly? If I do it by the getByName(...) method wouldn't it basically be the same thing?

And I'm not sure if I'm listening on TCP or UDP or both... I don't understand where that code goes (I assume you're talking about the Server, since I'm just using the LanScan code to search).
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #32 on: June 24, 2009, 01:57:40 PM »

It may be binding to 127.0.0.1.  You might try explicitly putting in the IP address or passing null for the InetAddress and see if that makes a difference.
Logged
Trussell
Jr. Member
**
Offline Offline

Posts: 52


View Profile
« Reply #33 on: June 26, 2009, 04:42:05 AM »

It's not binding to localhost. It's correctly binding to the LAN IP Address.
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #34 on: June 26, 2009, 12:36:19 PM »

Not sure what to tell you...
Logged
Pages: 1 2 3 [All]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.417 seconds with 20 queries.