title: Java: Networking / Sockets
body: <p>I'm having some issues for creating a simple socket, I'm new to this kind of stuff sorry for a simple question thanks. I tried to follow some tutorial for creating Sockets in java and tried this so far</p>
  
  <pre><code>try {
         Socket chatSocket = new Socket("127.0.0.1", 4242);
         System.out.println("connection established");    
      } 
  catch (IOException e) {
          e.printStackTrace();
  }
  </code></pre>
  
  <p>I'm getting this kind of error </p>
  
  <pre><code>java.net.ConnectException: Connection refused: connect
  at java.net.DualStackPlainSocketImpl.connect0(Native Method)
  at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
  at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
  at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
  at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
  at java.net.PlainSocketImpl.connect(Unknown Source)
  at java.net.SocksSocketImpl.connect(Unknown Source)
  at java.net.Socket.connect(Unknown Source)
  at java.net.Socket.connect(Unknown Source)
  at java.net.Socket.&lt;init&gt;(Unknown Source)
  at java.net.Socket.&lt;init&gt;(Unknown Source)
  at application.main.main(main.java:15)
  </code></pre>
  
  <p>and when I try to access my localhost from my browser I see this error</p>
  
  <pre><code>The connection to '127.0.0.1' failed. 
  Error: ConnectionRefused (0x274d). 
  System.Net.Sockets.SocketException No connection could be made because the 
  target machine actively refused it 127.0.0.1:4242
  </code></pre>
  
  <p>I have no idea what is happening because, just followed what the tutorial does. I think the issue is on my local machine but I have no idea what is making the connection refuse</p>