0

I have developed an application that allows multiple players to play together on line at various games such shifumi, poker, chess and so on. It works very well on my localhost. I would like to publish it. So I decided to use openshift to do this.

But there is a problem.

It seems it come from this statement : new ServerSocket(0). I do this inside the doPost method of an HttpServlet.

Could you tell me I don't have the permission to do this (new ServerSocket(0)) inside an openshift server?

edwardmp
  • 6,339
  • 5
  • 50
  • 77
gero
  • 1
  • 1
  • Can you post the error message/stack trace that you get from that piece of code? Along with a few specifics about what you are trying to accomplish? –  Feb 17 '15 at 18:09

1 Answers1

0

I think you have a couple of issues going on here.

The first is that when you call new ServerSocket(0), it is going to try to find a socket that it can bind to, probably on either 0.0.0.0 (all ip addresses/interfaces) or 127.0.0.1, neither of which is allowed on OpenShift.

According to the documentation (located here: http://download.java.net/jdk7/archive/b123/docs/api/java/net/ServerSocket.html) you can use one of the overloaded methods to provide an ip address to bind to, which should be your OPENSHIFT__IP (where could be jbosseap, jbossas, wildfly, jbossews, etc).

ServerSocket(int port, int backlog, InetAddress bindAddr)

Your second issue is a bit more complicated, basically what ports you can bind to. OpenShift allows user code to bind to ports 15000-20000, depending on what ports are not being used by other applications or services. However, none of those ports are open to the public internet, they are all internal ports for internal communications, so if you are trying to let a client connect to them, it won't work. The only ports that are publicly available are 80/443/8000/8443, and your application must bind to port 8080 on your OPENSHIFT__IP to be able to be reached using your app-domain.rhcloud.com public url. You can check out this article to read more about how all of the binding and routing works: https://developers.openshift.com/en/managing-port-binding-routing.html

Hopefully that answers the question about why that piece of code is not working.

  • Thanks. I understand my mistake. I though new ServerSocket(0) was able to automatically find the good address. But it was idiot. How could it do this. The lack of address means to use the localhost, that it. For the second issue, I don't again how to resolve it, but I'll try. – gero Feb 20 '15 at 18:38