简体   繁体   中英

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. And therefore two clients: a web client and an android client, all of them work wonderfully locally. 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. someone could help me configure the netty-socketIO server to accept all requests from any address on port 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

@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

private void clientIO(){

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

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. 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

There are 2 possible solutions

  1. You can use the public IP (the way suggested by @Ruslan)
  2. Also, the Jelastic platform resolver supports the WebSocket proxying (if the "Upgrade: websocket" header is present). 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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