Search code examples
javaopenshiftserversocket

java.net.BindException When Creating ServerSocket on Tomcat 7 on OpenShift


I was trying to launch a application on Openshift which listens to a port via ServerSocket.

ServerSocket  = new ServerSocket(8080); 

But it failed with the following error message:

java.net.BindException: Permission denied
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:376)
at java.net.ServerSocket.bind(ServerSocket.java:376)
at java.net.ServerSocket.<init>(ServerSocket.java:237)
at java.net.ServerSocket.<init>(ServerSocket.java:128)...

I've tried to change the port from 8080 to 8000, and then to 15000. But none of them worked.

I did search intensively on the Internet. However, I still cannot find a solution. Does anyone have a clue?


2015-12-29 edited

Proposed Reason:

Openshift allows gears to bind to port 8080. But Tomcat has already bound 8080. So, my application is disallowed binding to the same port.

Proposed Solution:

Use DIY Cart instead. But it seems that Openshift only allows external client to connect with http://, https://, ws:// and wss:// protocol (OpenShift Developer Guide). Applications should be modified to handle these protocols.

Ungarida confirmed the solution and provided documentation.


Solution

  • I think is the only solution, take a look to this documentation.