title: Sockets in Java...?
body: <p>I need to build an application which can receive data from over a network and use this data to do some unrelevant things with.</p>
  
  <p>Here's a piece of code to make clear what I'm doing.</p>
  
  <p>On the server side:</p>
  
  <pre><code>static Socket client = null;
  static ServerSocket ss = null;
  
  if (ss != null) {
                  ss.close();
              }
              ss = new ServerSocket(5513);
              isrunning = true;
              System.out.println("Waiting for client...");
              client = ss.accept();
              System.out.println("Client accepted.");
              BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
  </code></pre>
  
  <p>And the client side:</p>
  
  <pre><code>Socket client = null;
  PrintWriter out = null;
                      try {                            
                          client = new Socket("hostname", 5513);
                          out = new PrintWriter(client.getOutputStream(), true);
      }
  </code></pre>
  
  <p>Please note that this is just a piece of the code. There are no errors in the code.</p>
  
  <p>After running the server-sided piece of code, it correctly waits for the client to connect.</p>
  
  <p>Now here comes the problem. As soon as I try to connect from the client side, I'm getting a "connection refused"-error.</p>
  
  <p>HOWEVER, I found something on the internet whoch told me to try telnetting from the client side. For example, let the server-sided IP be 192.168.1.1. So, after using this command:</p>
  
  <pre><code>    telnet 192.168.1.1 5513
  </code></pre>
  
  <p>I actually get a connection with the server. The command will launch an empty screen, and everything I manually type in the command line will be sent to the server-side after pressing enter (checked with debugging). </p>
  
  <p>So, I can manually connect to the server-side and send some data, but my code refuses to connect.</p>
  
  <p>Anyone who knows what I am doing wrong?</p>