CHanged ip to local ip because port forwarding may be subjective to change.
This commit is contained in:
@@ -27,7 +27,8 @@ public class HttpMatchBrowserClient extends Thread {
|
|||||||
|
|
||||||
for (int i = 0; i < cons.length(); i++) {
|
for (int i = 0; i < cons.length(); i++) {
|
||||||
JSONObject con = (JSONObject) cons.get(i);
|
JSONObject con = (JSONObject) cons.get(i);
|
||||||
connections.add(new RaceConnection((String) con.get("ip_address"), con.getInt("port"), "Boat Game"));
|
//using "ip_address" will give their public ip
|
||||||
|
connections.add(new RaceConnection((String) con.get("local_ip"), con.getInt("port"), "Boat Game"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.sleep(5000);
|
Thread.sleep(5000);
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ import org.apache.http.message.BasicNameValuePair;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,8 +38,32 @@ public class HttpMatchBrowserHost extends Thread {
|
|||||||
httpMatchBrowserHost = this;
|
httpMatchBrowserHost = this;
|
||||||
httpClient = HttpClients.createDefault();
|
httpClient = HttpClients.createDefault();
|
||||||
|
|
||||||
|
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
|
||||||
|
int count = 0;
|
||||||
|
String ip = "";
|
||||||
|
while(e.hasMoreElements())
|
||||||
|
{
|
||||||
|
if (count > 3){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
NetworkInterface n = (NetworkInterface) e.nextElement();
|
||||||
|
Enumeration<InetAddress> ee = n.getInetAddresses();
|
||||||
|
while (ee.hasMoreElements())
|
||||||
|
{
|
||||||
|
InetAddress i = ee.nextElement();
|
||||||
|
if (count == 3){
|
||||||
|
ip = i.getHostAddress();
|
||||||
|
System.out.println(ip);
|
||||||
|
count++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Request parameters and other properties.
|
// Request parameters and other properties.
|
||||||
params = new ArrayList<>(2);
|
params = new ArrayList<>(2);
|
||||||
|
params.add(new BasicNameValuePair("ip", ip));
|
||||||
params.add(new BasicNameValuePair("port", "4942"));
|
params.add(new BasicNameValuePair("port", "4942"));
|
||||||
params.add(new BasicNameValuePair("magic", "Thomas and Seng"));
|
params.add(new BasicNameValuePair("magic", "Thomas and Seng"));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user