title: Failure to Accept Socket Connection in Java
body: <p>I'm trying to make a simple program with a server and client, passing text strings back and forth. I'm having trouble making the connection. I have a test printing line right below the socket accept line and it never prints, so I assume the problem is there, but I'm not sure how to do a more thorough check.</p>
  
  <p>I have written this program in Eclipse if that makes a difference. </p>
  
  <p>This is the server: </p>
  
  <pre><code>import java.io.*;
  import java.net.*;
  
  public class HW2Q1S {
  
  public static void main(String[] args) throws Exception {
  
      try {
          //connection
          ServerSocket srvr = new ServerSocket(7654);
          Socket skt = srvr.accept();
          System.out.println(skt.getPort());
  
          //data xfer
          BufferedReader sIn = new BufferedReader(new InputStreamReader(skt.getInputStream()));
          PrintWriter sOut = new PrintWriter(skt.getOutputStream(), true);
  
          //string receiving
          int count = 1;
          String msg = "";
  
          while((msg = sIn.readLine()) != null) {
              while(count &lt; 11) {
                  msg = sIn.readLine();
                  System.out.println("Received: "+ msg);
                  String returnMsg = msg.toUpperCase();
                  System.out.println("Capped: "+ returnMsg);
                  sOut.write(returnMsg);
                  count++;
              } 
          } //end of read from client in while loop
          if (count == 10) {
              System.out.println("Max reached.");
          }
          srvr.close();
          return;
      }
  
      catch(Exception e) {
          System.out.println("Error caught: " + e);
      }
  
  } // end of main
  } // end of class
  </code></pre>
  
  <p>And this is the client:</p>
  
  <pre><code>import java.util.Random;
  import java.io.*;
  import java.net.*;
  
  public class HW2Q1C {
  
  public static void main(String[] args) throws IOException {
  
      String capped = "";
      String temp = "";
  
      try {
          //make the connection
          Socket skt = new Socket("localhost", 7654);
          BufferedReader cIn = new BufferedReader(new InputStreamReader(skt.getInputStream()));
          PrintWriter cOut = new PrintWriter(skt.getOutputStream(), true);
  
          //send 11 strings
          for (int i = 0; i &lt; 11; i++) {
              temp = Stringer();
              cOut.write(temp);
              System.out.println("Sending: " + temp);
  
          }
  
          //receive server strings
          while(cIn.readLine() != null) {
          capped = cIn.readLine();
          System.out.println("From server: "+ capped);
          }
  
          skt.close();
      } // end of connection try block
  
      catch(Exception e) {
          System.out.print("Whoops! It didn't work!\n");
      }
  
  } //end of main
  
  static String Stringer() {
      String msg, alpha;
      msg = "";
      alpha = "abcdefghijklmnopqrstuvwxyz";
      Random rnd = new Random();
      for (int i = 0; i &lt; 10; i++) {
          msg += alpha.charAt(rnd.nextInt(25));
      }
      return msg;
  }
   } //end of class
  </code></pre>
  
  <p>Thanks!</p>