When you start the client-server application CHATA crashes the error indicated in the header

First of all I start the Server, everything is OK. Then I launch the client, enter my login through the console, and when I enter a message, an error flies and refers everything to InputStream is = http.getInputStream(); Prompted that you need to resolve this issue through the Firewall. But I have no idea how to do it. I read other answers, I did not find anything for my problem.

 public class GetThread implements Runnable { private final Gson gson; private int n; public GetThread() { gson = new GsonBuilder().create(); } @Override public void run() { try { while ( ! Thread.interrupted()) { URL url = new URL(Utils.getURL() + "/get?from=" + n); HttpURLConnection http = (HttpURLConnection) url.openConnection(); InputStream is = http.getInputStream(); try { byte[] buf = requestBodyToArray(is); String strBuf = new String(buf, StandardCharsets.UTF_8); JsonMessages list = gson.fromJson(strBuf, JsonMessages.class); if (list != null) { for (Message m : list.getList()) { System.out.println(m); n++; } } } finally { is.close(); } Thread.sleep(500); } } catch (Exception ex) { ex.printStackTrace(); } } private byte[] requestBodyToArray(InputStream is) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[10240]; int r; do { r = is.read(buf); if (r > 0) bos.write(buf, 0, r); } while (r != -1); return bos.toByteArray(); } } public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); try { System.out.println("Enter your login: "); String login = scanner.nextLine(); Thread th = new Thread(new GetThread()); th.setDaemon(true); th.start(); System.out.println("Enter your message: "); while (true) { String text = scanner.nextLine(); if (text.isEmpty()) break; Message m = new Message(login, text); int res = m.send(Utils.getURL() + "/add"); if (res != 200) { // 200 OK System.out.println("HTTP error occured: " + res); return; } } } catch (IOException ex) { ex.printStackTrace(); } finally { scanner.close(); } } } 

Full list of errors:

java.net.ConnectException: Connection: java.net.DualStackPlainSocketImpl.connect0 (Native Method) at java.net.DualStackPlainSocketImpl.socketConnect (DualStackPlainSocketImpl.java:79) at java.net.AbstractPoSocketImltllImpl.java:79 at java.net.DAlStackPlainSocketImpl.sonectImpl.socketImpl.socketImpl.socketImpl.socketImpl.ocketImpl.ocketImpl.socketImpl.socketImpl.socketImpl.socketImpl.socketImpl.socketImpl.socketImpl.socketImpl.socketImpl.socketConnect0 350) at java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java:188) at java.net.PlainSocketImpl.connect (in the program, in the form of the application, in the program, in the application, in the java.net.AbstractPlainSocketImpl.java:188) at the java.net.AbstractPlainSocketImpl.connect. net.SocksSocketImpl.connect (SocksSocketImpl.java天92) at java.net.Socket.connect (Socket.javainter89) at java.net.Socket.connect (Socket.java 12.38) at sun.net.NetworkClient.doConnect (NetworkClient.java:180) at sun.net.www.http.HttpClient.openServer (HttpClient.java:463) at sun.net.www.http.HttpClient.openServer (HttpClient.java low58) at sun.net. www.http.HttpClient. (HttpClient.java:242) at sun.net.www.http.HttpClient.New (HttpClient.javaι39) at sun.net.www.http.HttpClient.New (HttpClient.ja va: 357) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient (HttpURLConnection.java:1220) at sun.net.www.protocol.http.HttpURLConnection.plainConnect0 (HttpURLConnection.java:1156) unforgettable.htp.HttpURLConnection.plainConnect0 (HttpURLConnection.java:1156) you need to use). .www.protocol.http.HttpURLConnection.plainConnect (HttpURLConnection.java:1050) at sun.net.www.protocol.http.HttpURLConnection.connect (HttpURLConnection.java:984) at sun.net.www.protocol.http.hpnnection.java:984) at sun.net.www.protocol.http.htn.connecting.jacking .getInputStream0 (HttpURLConnection.java:1564) at sun.net.www.protocol.http.HttpURLConnection.getInputStream (HttpURLConnection.java:1492) at com.company.GetThread.run (GetThread.java:28) at java.lang. Thread.run (Thread.java:748)

  • not enough information, add code - Komdosh
  • Look in the debug or output to the console the address to which the code refers: Utils.getURL() + "/get?from=" + n Check if it is possible to open this address with the browser. - Sergei Petunin

0