CHanged ip to local ip because port forwarding may be subjective to change.

main
Fan-Wu Yang 8 years ago
parent 3d292f784b
commit 52271d580f

@ -27,7 +27,8 @@ public class HttpMatchBrowserClient extends Thread {
for (int i = 0; i < cons.length(); 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);

@ -13,7 +13,10 @@ import org.apache.http.message.BasicNameValuePair;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
/**
@ -35,8 +38,32 @@ public class HttpMatchBrowserHost extends Thread {
httpMatchBrowserHost = this;
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.
params = new ArrayList<>(2);
params.add(new BasicNameValuePair("ip", ip));
params.add(new BasicNameValuePair("port", "4942"));
params.add(new BasicNameValuePair("magic", "Thomas and Seng"));

Loading…
Cancel
Save