As the title says, I have my server running on a local machine, I tested and debugged it and it worked perfectly (server is written in java as well). But when I tried to test it with my remote IP (instead of 192.168.0.113 I used 146.255.x.x), and the server didn't receive anything, while the client has thrown this:
09-04 18:23:27.595: W/System.err(24241): java.net.ConnectException: failed to connect to /146.255.x.x (port 4040): connect failed: ECONNREFUSED (Connection refused)
09-04 18:23:27.595: W/System.err(24241): at libcore.io.IoBridge.connect(IoBridge.java:114)
09-04 18:23:27.595: W/System.err(24241): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
09-04 18:23:27.595: W/System.err(24241): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
09-04 18:23:27.595: W/System.err(24241): at java.net.Socket.startupSocket(Socket.java:566)
09-04 18:23:27.595: W/System.err(24241): at java.net.Socket.tryAllAddresses(Socket.java:127)
09-04 18:23:27.595: W/System.err(24241): at java.net.Socket.<init>(Socket.java:177)
09-04 18:23:27.595: W/System.err(24241): at java.net.Socket.<init>(Socket.java:149)
09-04 18:23:27.595: W/System.err(24241): at com.statenislandchat.Main$2$1$1.run(Main.java:146)
09-04 18:23:27.595: W/System.err(24241): Caused by: libcore.io.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
09-04 18:23:27.595: W/System.err(24241): at libcore.io.Posix.connect(Native Method)
09-04 18:23:27.600: W/System.err(24241): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
09-04 18:23:27.600: W/System.err(24241): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
09-04 18:23:27.600: W/System.err(24241): at libcore.io.IoBridge.connect(IoBridge.java:112)
09-04 18:23:27.600: W/System.err(24241): ... 7 more
I disabled the firewall on the server PC long ago, and I DID forward the ports on my router. I tried with some portscanners and they all detect a service on my port, but my client fails to reach it again and again.
SOLVED! It seems that that my router had client isolation active, which means that devices couldn't connect to each other on the same network. I tried connecting from a distant client and it worked.