RMI或与OpenShift上的Java程序的套接字连接 [英] RMI or socket connection to Java Program on OpenShift

查看:76
本文介绍了RMI或与OpenShift上的Java程序的套接字连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下简单情况:

我在OpenShift上创建了一个JBossAS7应用程序.我有一个index.jsp,每次加载它都会调用Java类.这个Java类收集一些数据并将其保存为字符串.我现在想做的是获取该字符串中包含的文本,但不将其显示在页面上.

I have created a JBossAS7 application on OpenShift. I have an index.jsp that calls a Java Class every time it's loaded. This Java class gathers some data and saves it as a string. What I want to do now is get the text contained in that String, but NOT have it displayed on the page.

我需要一种机制,例如RMI或我可以连接到套接字的套接字,并且可以使用客户端程序简单地接收String.不幸的是,OpenShift会阻止所有端口,并且我无法使用RMI或套接字绑定任何东西(我总是会拒绝权限).

What I need is a mechanism like RMI or a socket that I can connect to and simply receive the String using a client program. Unfortunately, OpenShift blocks all ports and I cannot use RMI or sockets to bind to anything (I always get permission denied).

有没有办法解决这个问题? 谢谢!

Is there a way to solve this? Thanks!

推荐答案

我解决此问题的方法非常简单,但是在论坛或留言板上的解释和记录却很少.

The way I solved this is rather straightforward, but poorly explained and documented on forums or message boards.

OpenShift仅允许用户绑定15000和35530之间的端口.但是,这样做时,用户还必须指定主机的IP地址,否则将使用localhost,这在OpenShift上是不允许的.服务器的地址位于环境变量OPENSHIFT_JBOSSAS_IP下(我使用的是JBoss AS 7.1,根据所使用的技术,该变量的名称可能有所不同).通过SSH登录到我的应用程序并运行env命令,我发现了这一点.

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_JBOSSAS_IP (I am using JBoss AS 7.1, the variable might have a different name based on whatever technology is used). I found that out by logging into my application via SSH and running the env command.

一旦程序在OpenShift上启动并且端口绑定到正确的IP地址,则用户必须转发端口才能连接到该端口.可以通过eclipse或使用RHC工具来完成. OpenShift上的端口转发意味着OpenShift服务器上的绑定端口将映射到用户本地主机上的相同端口.编写客户端程序时,用户必须连接到localhost:PORT而不是IP_ADDRESS_OF_OPENSHIFT_SERVER:PORT.这是我花了一段时间才了解的东西.一旦一切正常,客户端程序就可以正常运行.

Once the program is started on OpenShift and the port bound to the correct IP address, the user has to forward the port in order to connect to it. This can be done either from eclipse or using the RHC tools. Port forwarding on OpenShift means that the bound port on the OpenShift server will be mapped to the same port on the localhost of the user. When writing the client program, the user has to connect to localhost:PORT instead of IP_ADDRESS_OF_OPENSHIFT_SERVER:PORT. This was something that took a while for me to understand. Once I got everything right, the client program ran without a problem.

这篇关于RMI或与OpenShift上的Java程序的套接字连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆