title: Array of Sockets Java
body: <p>I'm creating server and client java applications. I would like to create an array to store my sockets in. I'm using eclipse, and when I type in this line:</p>
  
  <pre><code>Socket[] sockets = new Socket[3];
  </code></pre>
  
  <p>Eclipse gives me an error saying "The resource type Socket[] does not implement java.lang.AutoCloseable".</p>
  
  <p>How can I fix this?</p>
  
  <p>Thank you</p>
  
  <p>Try/Catch Statement:</p>
  
  <pre><code>try (
                  Socket[] sockets = new Socket[3]; //Line giving me error
                  ServerSocket serverSocket =
                      new ServerSocket(Integer.parseInt(ip));
                  Socket clientSocket = serverSocket.accept();     
                  ServerClient client = new ServerClient(clientSocket);
  
                  PrintWriter out =
                      new PrintWriter(clientSocket.getOutputStream(), true);                   
                  BufferedReader in = new BufferedReader(
                      new InputStreamReader(clientSocket.getInputStream()));
                  //User input
                  BufferedReader stdIn =
                      new BufferedReader(
                          new InputStreamReader(System.in))
              ) {
                  String inputLine;
                  while ((inputLine = in.readLine()) != null) {
                      out.println(inputLine);
                  }
              } catch (IOException e) {
                  System.out.println("Exception caught when trying to listen on port "
                      + port + " or listening for a connection");
                  System.out.println(e.getMessage());
                  continue;
              } catch (Exception e1) {
                  // TODO Auto-generated catch block
                  e1.printStackTrace();
              }
  </code></pre>