I am making an online java chat and I was testing it and when I used it on my other computer it wouldn't work at the same time as this PC or on the other one show the JTextBox-es on the other PC, here's the code i use to communicate the server to the client
Socket kkSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
kkSocket = new Socket("dargon.ddns.net", 7598);
out = new PrintWriter(kkSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("not work :/");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection");
System.exit(1);
}
And here's the servers code
public class Online {
public static void main(String[] args) throws IOException {
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(7598);
System.out.print("Online!");
} catch (IOException e) {
System.err.println("Could not listen on port: 7598.");
System.exit(1);
}
Socket clientSocket = null;
try {
clientSocket = serverSocket.accept();
System.out.print("Online!");
} catch (IOException e) {
System.err.println("Accept failed.");
System.exit(1);
}
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(
new InputStreamReader(
clientSocket.getInputStream()));
out.close();
in.close();
clientSocket.close();
serverSocket.close();
}
}