简体   繁体   English

如何配置 netty-SocketIO 服务器,以便可以从 jelastic 中的所有远程 java 客户端访问它

[英]How to configure the netty-SocketIO server so that it is accessible from all remote java clients in jelastic

I am developing a Spring-Boot project which also includes a socketIO server based on netty-socket Io.我正在开发一个 Spring-Boot 项目,其中还包括一个基于 netty-socket Io 的 socketIO 服务器。 And therefore two clients: a web client and an android client, all of them work wonderfully locally.因此有两个客户端:一个 web 客户端和一个 android 客户端,它们都在本地工作得很好。 But when I deploy online server in Jelastic only the web client which accesses netty-SocketIO server, but android client fails to connect to netty-SocketIO server.但是当我在 Jelastic 中部署在线服务器时,只有 web 客户端访问 netty-SocketIO 服务器,但 android 客户端无法连接到 netty-SocketIO 服务器。 someone could help me configure the netty-socketIO server to accept all requests from any address on port 8888有人可以帮我配置 netty-socketIO 服务器以接受来自端口 8888 上任何地址的所有请求

Server configuration服务器配置

Configuration config = new Configuration();

        //config.setHostname("sec.j.layershift.co.uk");
        config.setHostname("0.0.0.0");
        config.setPort(8888);


        final SocketIOServer server = new SocketIOServer(config);


        // Listen for client connections
        server.addConnectListener(client -> {
            System.out.println("************ Client: " + getIpByClient(client) + " Connected ************");


        });

Web client configuration Web客户端配置

@CrossOrigin("*")
@RestController
public class ClientLocation {

    Socket socket =null;
    EventBuilder eventBuilder =null;
    Gson gs =  new Gson();
    //................................


socket = IO.socket("http://sec.j.layershift.co.uk:8888");
            socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {

                @Override
                public void call(Object... args) {

                    ChatObject co = new ChatObject("ADMIN", "");
                    String infUser = gs.toJson(co);
                    System.out.println("\n"+infUser);
                    JSONObject jb =  new JSONObject();
                    try {

//                      jb.put("userName", co.getUserName());
//                      jb.put("message", co.getMessage());

                        jb =  new JSONObject(infUser);
                        socket.emit("username", jb);
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

Configuration of the java or android client java或android客户端的配置

private void clientIO(){

        try {
            socket = IO.socket("http://aug-sec.j.layershift.co.uk:8888");
            socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {

Nb. NB。 the configuration of the java or android client is identical to that of the web because all use the Socket.IO v1.0.0. the configuration of the java or android client is identical to that of the web because all use the Socket.IO v1.0.0. But only the web client works from the Jelastic host because it is in the same folder as the server and the java clients do not succeed, so everything works in localhost or in LAN但是只有 web 客户端可以从 Jelastic 主机工作,因为它与服务器位于同一文件夹中,并且 java 客户端不成功,因此一切都在本地主机或局域网中运行

There are 2 possible solutions有2种可能的解决方案

  1. You can use the public IP (the way suggested by @Ruslan)您可以使用公共 IP (@Ruslan 建议的方式)
  2. Also, the Jelastic platform resolver supports the WebSocket proxying (if the "Upgrade: websocket" header is present).此外,Jelastic 平台解析器支持 WebSocket 代理(如果“升级:websocket”header 存在)。 You can use the JELASTIC_EXPOSE variable to forward the requests from port 80 to 8888 (more info here https://docs.jelastic.com/container-ports/#ports-auto-redirect ) inside your container and then just access the app by your environment domain and port 80您可以在容器内使用 JELASTIC_EXPOSE 变量将请求从端口 80 转发到 8888(更多信息在这里https://docs.jelastic.com/container-ports/#ports-auto-redirect ),然后只需通过您的环境域和端口 80

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM