Michele Papale
Michele Papale

Reputation: 53

OpenFire server does not work with websockets

I am not able to use OpenFire server through WebSockets. This is the code client side I use to connect to the server:

    var ws = new WebSocket('ws://35.228.94.32:7070/ws-xmpp');

    ws.onopen = () => {
        // connection opened
        console.log('open')
    };

    ws.onmessage = (e) => {
        // a message was received
        console.log(e.data);
    };

    ws.onerror = (e) => {
        // an error occurred
        console.log("Error occured", e, e.message);
    };

    ws.onclose = (e) => {
        // connection closed
        console.log("Closing: ", e);
    };

This is the error I receive:

Error occured {"isTrusted": false, "message": "failed to connect to /35.228.94.32 (port 7070) from /192.168.232.2 (port 54028) after 10000ms"} failed to connect to /35.228.94.32 (port 7070) from /192.168.232.2 (port 54028) after 10000ms

Closing: {"isTrusted": false, "message": "failed to connect to /35.228.94.32 (port 7070) from /192.168.232.2 (port 54028) after 10000ms"}

I think it is a problem of OpenFire with websockets because if I try using xmpp protocol, it works. Can you help me?

Upvotes: 1

Views: 903

Answers (3)

Houssamel-deen
Houssamel-deen

Reputation: 69

  • just open following admin-page for openfire:
http://localhost:9090/index.jsp
  • then Server > Server Manager > Server Information > then Server Ports :-
1. HTTP Binding >> for example The port used for unsecured HTTP client connections: 7071
  • then: ws://localhost:7071/ws
2. HTTP Binding >> for example The port used for secured HTTP client connections: 7071
  • then: wss://localhost:7444/ws

Upvotes: 0

Michele Papale
Michele Papale

Reputation: 53

I've found the problem and it was not related to OpenFire. I run OpenFire on a Google Cloud machine and, by default, Google uses a firewall to block incoming requests. Hence, allowing requests to port 7070, it works.

Upvotes: 0

Guus
Guus

Reputation: 3006

Your endpoint does not seem correct. Try this instead:

ws://35.228.94.32:7070/ws

Optionally, if you want to use encryption, use:

wss://35.228.94.32:7443/ws

You will need to have set up proper certificates for that to work though.

Upvotes: 4

Related Questions