Preparing code to retrieve the server port over SSDP instead of using a defult port number.
This commit is contained in:
parent
2b86fb4ce6
commit
d5b40053fb
4 changed files with 16 additions and 12 deletions
|
|
@ -18,7 +18,6 @@ import com.coder.client.gui.selectProject.SelectProjectDialog;
|
|||
import com.coder.client.gui.selectProject.SelectProjectDialogListener;
|
||||
import com.coder.client.gui.selectServer.SelectServerDialog;
|
||||
import com.coder.client.gui.selectServer.SelectServerDialogListener;
|
||||
import com.coder.server.CoderServer;
|
||||
import com.coder.server.message.*;
|
||||
|
||||
import zutil.log.CompactLogFormatter;
|
||||
|
|
@ -92,8 +91,8 @@ public class CoderClient extends Application{
|
|||
try{
|
||||
selectServerDialog.setServerPort(Integer.parseInt(value));
|
||||
}catch(NumberFormatException e){
|
||||
logger.warning("port argument to program is not of a integer type. using default port.");
|
||||
selectServerDialog.setServerPort(CoderServer.SERVER_PORT);
|
||||
logger.warning("port argument to program is not of a integer type");
|
||||
selectServerDialog.setServerPort(-1);
|
||||
}
|
||||
}else if(key.equals("project")){
|
||||
selectProjectDialog.setProject(value);
|
||||
|
|
@ -109,7 +108,7 @@ public class CoderClient extends Application{
|
|||
}
|
||||
|
||||
//start program logic
|
||||
selectServerDialog.setServerPort(CoderServer.SERVER_PORT);
|
||||
selectServerDialog.setServerPort(-1);
|
||||
selectServerDialog.showOnStage(mainStage);
|
||||
|
||||
}
|
||||
|
|
@ -125,7 +124,7 @@ public class CoderClient extends Application{
|
|||
if(ssdpClient != null){
|
||||
ssdpClient.requestService("coder:discover");
|
||||
for(StandardSSDPInfo server : ssdpClient.getServices("coder:discover"))
|
||||
selectServerDialog.addServerToList(server.getInetAddress().getHostAddress());
|
||||
selectServerDialog.addServerToList(server.getInetAddress().getHostAddress(), 1337);
|
||||
}else{
|
||||
logger.severe("could not send a SSDP request since the client is not setup");
|
||||
}
|
||||
|
|
@ -424,7 +423,7 @@ public class CoderClient extends Application{
|
|||
@Override
|
||||
public void run() {
|
||||
String ip = service.getInetAddress().getHostAddress();
|
||||
selectServerDialog.addServerToList(ip);
|
||||
selectServerDialog.addServerToList(ip, 1337);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package com.coder.client;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.coder.server.message.*;
|
||||
|
||||
public interface CoderMessageReceivedListener {
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ public class SelectServerDialog extends GuiWindow {
|
|||
if(observable.getValue() != null){
|
||||
logger.fine("ServerListItem [" + observable.getValue() + "] selected in the server list");
|
||||
address = observable.getValue().getIP();
|
||||
port = observable.getValue().getPort();
|
||||
connectButton.setDisable(false);
|
||||
}else{
|
||||
connectButton.setDisable(true);
|
||||
|
|
@ -138,9 +139,9 @@ public class SelectServerDialog extends GuiWindow {
|
|||
return "Select Server";
|
||||
}
|
||||
|
||||
public void addServerToList(String ip) {
|
||||
public void addServerToList(String ip, int port) {
|
||||
logger.fine("Adding server \"" + ip + "\" to server list");
|
||||
ServerListItem item = new ServerListItem(ip);
|
||||
ServerListItem item = new ServerListItem(ip, port);
|
||||
this.serverList.add(item);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,17 +3,23 @@ package com.coder.client.gui.selectServer;
|
|||
class ServerListItem {
|
||||
|
||||
private String ip = null;
|
||||
private int port = -1;
|
||||
|
||||
public ServerListItem(String ip){
|
||||
public ServerListItem(String ip, int port){
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getIP(){
|
||||
return this.ip;
|
||||
}
|
||||
|
||||
public int getPort(){
|
||||
return port;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return "SERVER: ip="+ip;
|
||||
return "SERVER: ip="+ip+":"+port;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue