There is a VPS with a running Java application that is tied to port 4444. There is a client program that connects to port 4444 of the server (by its IP), but there is no result - no connection is made.

VPS on Ubuntu 14.04. What can be wrong? Maybe I need some more VPS ports to take into account in the client application?

Socket socket = new Socket(ip, 4444); //строка в клиенте, отвечающая за подключение ServerSocket srvSocket = new ServerSocket(4444); //строка в приложении на сервере 

On localhost, everything works fine.

  • The server is started via the command line in putty. Need to transfer to the putty port, in that case? - DenisNovac
  • It seems that the connection through the port itself putty does not help, even if you set the same port in ServerSocket on the server. - DenisNovac
  • The server is on SkyHost, but they have full root-rights there, there should not be something broken in this regard. - DenisNovac
  • I have serverSocket = new ServerSocket(PORT_NUMBER); on the server serverSocket = new ServerSocket(PORT_NUMBER); followed by Socket clientSocket = serverSocket.accept(); , and on one of the clients socket = new Socket(serverIP, serverPort); and it still works fine. Especially if your code on the localhost-e works properly, then the matter is unlikely in the code. Perhaps the server is standing and blocking incoming firewall connections? - Regent
  • Make sure the server starts. How does the program run? Background process or main? Make sure the port is open. In the second putty enter the netstat -n -a | greep 4444. The output should be 0.0.0.0:4444 LISTEN - Sergey

1 answer 1

Actually, I blocked the incoming connection to iptables, it became clear when I didn’t find this port in iptables -L -n, and the default entry policy was DROP: Chain INPUT (policy DROP). I tried to disable it with the command iptables -F even when I first encountered it, but this command was tightly freezing the server, and did not clean anything. And you can open ports with the command:

 iptables -P INPUT ACCEPT 

But, if it is not desirable to open all ports, you can only open a specific port 4444:

 iptables -I INPUT -p tcp --dport 4444 -m state --state NEW -j ACCEPT 

Thank you all for the tips.

  • And save the state with the service iptables save command. - DenisNovac