Preparing code to retrieve the server port over SSDP instead of using a defult port number.

This commit is contained in:
dcollin 2015-11-05 13:58:45 +01:00
parent 2b86fb4ce6
commit d5b40053fb
4 changed files with 16 additions and 12 deletions

View file

@ -18,7 +18,6 @@ import com.coder.client.gui.selectProject.SelectProjectDialog;
import com.coder.client.gui.selectProject.SelectProjectDialogListener; import com.coder.client.gui.selectProject.SelectProjectDialogListener;
import com.coder.client.gui.selectServer.SelectServerDialog; import com.coder.client.gui.selectServer.SelectServerDialog;
import com.coder.client.gui.selectServer.SelectServerDialogListener; import com.coder.client.gui.selectServer.SelectServerDialogListener;
import com.coder.server.CoderServer;
import com.coder.server.message.*; import com.coder.server.message.*;
import zutil.log.CompactLogFormatter; import zutil.log.CompactLogFormatter;
@ -92,8 +91,8 @@ public class CoderClient extends Application{
try{ try{
selectServerDialog.setServerPort(Integer.parseInt(value)); selectServerDialog.setServerPort(Integer.parseInt(value));
}catch(NumberFormatException e){ }catch(NumberFormatException e){
logger.warning("port argument to program is not of a integer type. using default port."); logger.warning("port argument to program is not of a integer type");
selectServerDialog.setServerPort(CoderServer.SERVER_PORT); selectServerDialog.setServerPort(-1);
} }
}else if(key.equals("project")){ }else if(key.equals("project")){
selectProjectDialog.setProject(value); selectProjectDialog.setProject(value);
@ -109,7 +108,7 @@ public class CoderClient extends Application{
} }
//start program logic //start program logic
selectServerDialog.setServerPort(CoderServer.SERVER_PORT); selectServerDialog.setServerPort(-1);
selectServerDialog.showOnStage(mainStage); selectServerDialog.showOnStage(mainStage);
} }
@ -125,7 +124,7 @@ public class CoderClient extends Application{
if(ssdpClient != null){ if(ssdpClient != null){
ssdpClient.requestService("coder:discover"); ssdpClient.requestService("coder:discover");
for(StandardSSDPInfo server : ssdpClient.getServices("coder:discover")) for(StandardSSDPInfo server : ssdpClient.getServices("coder:discover"))
selectServerDialog.addServerToList(server.getInetAddress().getHostAddress()); selectServerDialog.addServerToList(server.getInetAddress().getHostAddress(), 1337);
}else{ }else{
logger.severe("could not send a SSDP request since the client is not setup"); logger.severe("could not send a SSDP request since the client is not setup");
} }
@ -424,7 +423,7 @@ public class CoderClient extends Application{
@Override @Override
public void run() { public void run() {
String ip = service.getInetAddress().getHostAddress(); String ip = service.getInetAddress().getHostAddress();
selectServerDialog.addServerToList(ip); selectServerDialog.addServerToList(ip, 1337);
} }
}); });
} else { } else {

View file

@ -1,7 +1,5 @@
package com.coder.client; package com.coder.client;
import java.util.Map;
import com.coder.server.message.*; import com.coder.server.message.*;
public interface CoderMessageReceivedListener { public interface CoderMessageReceivedListener {

View file

@ -79,6 +79,7 @@ public class SelectServerDialog extends GuiWindow {
if(observable.getValue() != null){ if(observable.getValue() != null){
logger.fine("ServerListItem [" + observable.getValue() + "] selected in the server list"); logger.fine("ServerListItem [" + observable.getValue() + "] selected in the server list");
address = observable.getValue().getIP(); address = observable.getValue().getIP();
port = observable.getValue().getPort();
connectButton.setDisable(false); connectButton.setDisable(false);
}else{ }else{
connectButton.setDisable(true); connectButton.setDisable(true);
@ -138,9 +139,9 @@ public class SelectServerDialog extends GuiWindow {
return "Select Server"; return "Select Server";
} }
public void addServerToList(String ip) { public void addServerToList(String ip, int port) {
logger.fine("Adding server \"" + ip + "\" to server list"); logger.fine("Adding server \"" + ip + "\" to server list");
ServerListItem item = new ServerListItem(ip); ServerListItem item = new ServerListItem(ip, port);
this.serverList.add(item); this.serverList.add(item);
} }

View file

@ -3,17 +3,23 @@ package com.coder.client.gui.selectServer;
class ServerListItem { class ServerListItem {
private String ip = null; private String ip = null;
private int port = -1;
public ServerListItem(String ip){ public ServerListItem(String ip, int port){
this.ip = ip; this.ip = ip;
this.port = port;
} }
public String getIP(){ public String getIP(){
return this.ip; return this.ip;
} }
public int getPort(){
return port;
}
public String toString(){ public String toString(){
return "SERVER: ip="+ip; return "SERVER: ip="+ip+":"+port;
} }
} }