我有一臺服務器將在另一臺機器上運行,我需要使用兩臺不同的機器進行調試。有沒有辦法虛擬調試服務器,因爲在我的機器上一切運行正常,但當我把它放在另一臺機器上一切都錯了?我沒有擁有另一臺機器(我只能託管並查看結果)。如何調試服務器
public class fss { public static void main(String[] args) throws IOException { ServerSocket serverSocket = null; boolean listening = true; boolean allowed = true; // int port = Integer.parseInt(args[0]); int port
= 60000;
try {
serverSocket = new ServerSocket(port);
} catch (IOException e) {
System.out.println("Could not transmit on port: " + port);
System.exit(-1);
}
while (listening) {
//Take the ip of the client in number form
allowed = true;
Socket socket = serverSocket.accept();
DataOutputStream outToClient = new DataOutputStream(socket.getOutputStream());
String clientAddress = socket.getRemoteSocketAddress().toString();
clientAddress = clientAddress.substring(1);
for (int i = 0; i < clientAddress.length() - 1; i++) {
if (clientAddress.substring(i, i + 1).equals(":")) {
clientAddress = clientAddress.substring(0, i);
}
}
File f = new File("forbidden.txt");
if (f.exists()) {
BufferedReader forbidden = new BufferedReader(new FileReader("forbidden.txt"));
String addr;
while ((addr = forbidden.readLine()) != null) {
if (Character.isLetter(addr.charAt(0))) {//if the address is in a letter form
addr = InetAddress.getByName(addr).toString();
for (int i = 0; i < addr.length() - 1; i++) {
//System.out.println(addr.substring(i, i + 1));
if (addr.substring(i, i + 1).equals("/")) {
addr = addr.substring(i + 1);
}
}
}
if (clientAddress.equals(addr)) {
allowed = false;
break;
}
}
if (allowed == true) {
new MultiThread(socket).start();
} else {
outToClient.writeBytes("Connection refused" + "\n");
socket.close();
forbidden.close();
}
} else {
new MultiThread(socket).start();
}
}
serverSocket.close();
}
}