/** Open a server connection. */ public boolean openServerConnection() { if (myServer != null) { myServer.close(); myServer = null; } try { // Opens the connection on any open port. ServerSocket s = new ServerSocket(0); myServer = new NetworkServer(this, s); // We don't want to reset our identifier after we've already // opened a connection, since someone else might identify us // through it. if (myServerHash == 0) { setServerHash(getHostIdentifier(InetAddress.getLocalHost(), myServer.getPort())); } } catch (IOException ioe) { // This means the socket could not be opened. myServer = null; error("Could not open server connection: " + ioe.getMessage()); return false; } myServer.start(); return true; }
public int getServerPort() { return myServer.getPort(); }