-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c98451
commit a540cd5
Showing
9 changed files
with
67 additions
and
12 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
package client; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
|
||
public class Controller { | ||
private Client client; | ||
|
||
public Controller() throws UnknownHostException { | ||
client = new Client(InetAddress.getLocalHost(), 62000); | ||
public Controller() throws IOException { | ||
String ip = loadIpAddress(); | ||
client = new Client(InetAddress.getByName(ip), 62000); | ||
} | ||
public Client getClient() { | ||
return client; | ||
} | ||
private String loadIpAddress() throws IOException{ | ||
File f = new File(this.getClass().getResource("data/config.txt").getFile()); | ||
BufferedReader in = new BufferedReader( new FileReader(f) ); | ||
String res = in.readLine(); | ||
in.close(); | ||
|
||
return res; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
127.0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package server; | ||
|
||
import java.io.File; | ||
|
||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
|
||
import org.w3c.dom.Document; | ||
|
||
public class ServerConfiguration { | ||
private static ServerConfiguration instance = null; | ||
|
||
private int port; | ||
|
||
private ServerConfiguration(){ | ||
this.load(); | ||
} | ||
|
||
static ServerConfiguration getInstance(){ | ||
if (!(instance instanceof ServerConfiguration)){ | ||
instance = new ServerConfiguration(); | ||
} | ||
return ServerConfiguration.instance; | ||
} | ||
|
||
private void load(){ | ||
|
||
try { | ||
File fXmlFile = new File(this.getClass().getResource("data/config.xml").getFile()); | ||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); | ||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); | ||
Document doc = dBuilder.parse(fXmlFile); | ||
|
||
this.port = Integer.parseInt( doc.getElementsByTagName("port").item(0).getTextContent() ); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
System.exit(-1); | ||
} | ||
} | ||
|
||
int getPort(){ | ||
return this.port; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<port>62000</port> |