exavance jones exavance jones - 5 months ago 83
Java Question

Wanted to host Raw socket program in JAVA on openshift

I have looked for similar query on many forums including stack Overflow, but out of luck. I have created DIY application on openshift and installed java along with Apache web server, the web server works fine over their, but now am looking to host RAW TCP socket based program, to listen at 8080 port on openshift, the program runs in openshift console, I see the Server Listening... message but when I try to connect my socket client from my system, it just retry for few seconds, and then it says, connections reset by peer, what should I do now, or is there any alternative solution to this?

Thanks!

Answer

It seems you are trying to connect to port 8080 with your client:

echoSocket = new Socket(serverHostname, 8080);

OpenShift only allows ports between 15000 and 35530 to be bound by a user. However, when doing so the user must also specify the IP address of the host, otherwise localhost will be used, which is not allowed on OpenShift. The address of the server is located under the environment variable OPENSHIFT_DIY_IP (If using JBoss , the variable might have a different name based on whatever technology is used, as in your case it is DIY).

The server still needs to be bound to 8080 to be externally reachable, but clients should connect to 80 or 8000 (websockets) actually. See this diagram for details on how to route requests on OpenShift.

enter image description here

Check the terminal output when pushing code, to see whether your action hook that is launching the server works. Make sure to have the hook file executable.

See this for more information

Port Binding and Routing Requests to your OpenShift Application

So, overall only websocket or HTTP traffic is allowed by the HAProxy in your application cartridges , any traffic having protocol other than this will not be passed through it. So better you use websocket, instead of using RAW sockets.

Comments