我编写了简单的服务器 - 客户端程序,用于将信息从客户端发送到服务器,但它不能解决以下错误:
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
ERROR: transport error 202: connect failed: Permission denied
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [debugInit.c:750]
也有以下例外:
java.net.SocketException: Permission denied: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at net.inthemoon.localhostconnectattempt.LocalhostConnectAttempt$2.run(LocalhostConnectAttempt.java:56)
at java.lang.Thread.run(Unknown Source)
代码如下:
package net.inthemoon.localhostconnectattempt;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
public class LocalhostConnectAttempt {
private static String hostName = "localhost";
private static int portNumber = 444;
public static void main(String[] args) throws InterruptedException {
Thread server = new Thread(new Runnable() {
@Override
public void run() {
try (
ServerSocket serverSocket = new ServerSocket(portNumber);
Socket clientSocket = serverSocket.accept();
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
) {
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println("Server: " + inputLine);
out.println("heard you");
if (inputLine.equals("bye")) {
System.out.println("Server: exiting");
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
server.setDaemon(true);
server.start();
Thread client = new Thread( new Runnable() {
@Override
public void run() {
try (
Socket kkSocket = new Socket(hostName, portNumber);
PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(
new InputStreamReader(kkSocket.getInputStream()));
) {
out.println("Hello world!");
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
Thread.sleep(5000);
client.start();
}
}
更新
在localhost 127.0.0.1
文件中披露hosts
没有帮助。
更新2
我找到了问题的根源:这是由[代理自动配置] [1]引起的。由于某种原因,127.0.0.1
的地址是由代理处理并且通向代理服务器的网页。
function FindProxyForURL(url,host)
{
if( host == '127.0.0.1' ) {
return "DIRECT";
}
到wpad.dat
有帮助,但我仍然不明白整个效果。我有很长一段时间的代理,以前没有造成这样的影响。
所以我认为这也与IPv6
或某事有关。