title: Trying to make a simple echo client server program work between two computers
body: <p>I have been trying to resolve this issue but with no success so finally i am here to get some help from experts.</p>
  
  <p>I just wanted to make a simple client server program work between two computers. </p>
  
  <p>The server will reside in my laptop which is connected to the internet through a linksys router.</p>
  
  <p>The client will reside in a university computer. I scped the file to a university computer and then i run it through ssh.</p>
  
  <p>Now also two things worth noting is that i have also disabled firewall in my computer as well as i have configured port forwaring in my linksys router i.e it will forward request to the port to my ipaddress. I have also made my ipadddress static. </p>
  
  <p>Here is the server code to reside in my laptop.</p>
  
  <pre><code>/* EchoServer.java
   *
   * Copyright (c) 2000 Sean Walton and Macmillan Publishers.  Use may be in
   * whole or in part in accordance to the General Public License (GPL).
   *
   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
  */
  
  /*****************************************************************************/
  /*** EchoServer.java                                                       ***/
  /***                                                                       ***/
  /*****************************************************************************/
  
  import java.io.*;
  import java.net.*;
  
  public class EchoServer
  {
      public EchoServer(int portnum)
      {
          try
          {
              server = new ServerSocket(portnum);
          }
          catch (Exception err)
          {
              System.out.println(err);
          }
      }
  
      public void serve()
      {
          try
          {
              while (true)
              {
  
                  Socket client = server.accept();
  
                  BufferedReader r = new BufferedReader(new InputStreamReader(client.getInputStream()));
                  PrintWriter w = new PrintWriter(client.getOutputStream(), true);
                  w.println("Welcome to the Java EchoServer.  Type 'bye' to close.");
                  String line;
                  do
                  {
                      line = r.readLine();
                      if ( line != null )
                          w.println("Got: "+ line);
                  }
                  while ( !line.trim().equals("bye") );
                  client.close();
              }
          }
          catch (Exception err)
          {
              System.err.println(err);
          }
      }
  
      public static void main(String[] args)
      {
          EchoServer s = new EchoServer(3000);
          s.serve();
      }
  
      private ServerSocket server;
  }
  </code></pre>
  
  <p>Here is the client code that will reside in university computer.</p>
  
  <pre><code>/* EchoClient.java
   *
   * Copyright (c) 2000 Sean Walton and Macmillan Publishers.  Use may be in
   * whole or in part in accordance to the General Public License (GPL).
   *
   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
  */
  
  /*****************************************************************************/
  /*** EchoClient.java                                                       ***/
  /***                                                                       ***/
  /*****************************************************************************/
  
  import java.io.*;
  import java.net.*;
  
  public class EchoClient
  {
      public static void main(String[] args)
      {
          try
          {
              Socket s = new Socket("my static ip address here", 3000);
              BufferedReader r = new BufferedReader(new InputStreamReader(s.getInputStream()));
              PrintWriter w = new PrintWriter(s.getOutputStream(), true);
              BufferedReader con = new BufferedReader(new InputStreamReader(System.in));
              String line;
              do
              {
                  line = r.readLine();
                  if ( line != null )
                      System.out.println(line);
                  line = con.readLine();
                  w.println(line);
              }
              while ( !line.trim().equals("bye") );
          }
          catch (Exception err)
          {
              System.err.println(err);
          }
      }
  }
  </code></pre>
  
  <p>When i run it(both). The client program runs and it halts without any error. It just hangs.</p>
  
  <p>I appreciate your help very much!</p>