add Server bind option (#2356) and todo notes

This commit is contained in:
Ben Fry
2014-05-10 20:22:44 -04:00
parent 30268618ab
commit 95de8998cb
3 changed files with 49 additions and 30 deletions

View File

@@ -67,11 +67,25 @@ public class Server implements Runnable {
* @param port port used to transfer data
*/
public Server(PApplet parent, int port) {
this(parent, port, null);
}
/**
* @param parent typically use "this"
* @param port port used to transfer data
* @param host when multiple NICs are in use, the ip (or name) to bind from
*/
public Server(PApplet parent, int port, String host) {
this.parent = parent;
this.port = port;
try {
server = new ServerSocket(this.port);
if (host == null) {
server = new ServerSocket(this.port);
} else {
server = new ServerSocket(this.port, 10, InetAddress.getByName(host));
}
//clients = new Vector();
clients = new Client[10];
@@ -168,8 +182,8 @@ public class Server implements Runnable {
return InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
return null;
}
return null;
}