我在将客户端和服务器连接在一起时遇到了一些问题。客户端只是试图到达服务器。
我已经在网络上完成了以下问题排查:
我没有选择,也不知道发生了什么。
如果有什么建议可以从哪里开始确定我的问题的原因,那将是很好的,我只是迷失在哪里从这里诊断。代码如下。如果有人认为这是我已经测试过的东西,我甚至会重试一些步骤。
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;
import java.util.EventListener;
public class Client{
private static Socket socket;
private static PrintWriter printWriter;
private int portNumber = 1337;
private String hostName = "234.123.1.234";//Not real IP, made up ip address to demonstrate code to stack overflow users
public static void main(String[] args){
new Client().validateSecurity();
}
public void validateSecurity(String key){
try {
Socket kkSocket = new Socket(hostName, portNumber);
PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(
new InputStreamReader(kkSocket.getInputStream()));
}catch(Exception e){
}
}
}
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;
import java.util.EventListener;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Server{
private static Socket socket;
private static PrintWriter printWriter;
private int portNumber = 1337;
public static void main(String[] args){
new Server().validateSecurity("hi");
}
public void validateSecurity(String key){
try
{
ServerSocket serverSocket = new ServerSocket(portNumber);
System.out.println("WAITING ON CONNECTION");
Socket clientSocket = serverSocket.accept();
System.out.println("CONNECTION ACCEPTED");
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
}catch(Exception e){
e.printStackTrace();
}
}
}
答案 0 :(得分:0)
连接超时几乎总是表示防火墙问题。