0

I have domain (for example: mydomain.com)

I want to connect to socket via domain

P.S. now I'm connecting to local websocket var socket = new WebSocket("ws://localhost:8080");

How can I keep webserver and websocket on 80 port (coz they are conflicting)?

And how can I make connection to socket using domain (like this: var socket = new WebSocket("ws://echo.websocket.org");)?

I read about apache proxy... but I can't understand what should I do...

I'm using OpenServer

<script>
window.onload = function(){
    var socket = new WebSocket("ws://localhost:8080");
    var status = document.querySelector("#status");

    socket.onopen = function() {
        status.innerHTML += `<i class="ui orange label">Connected</i>`;
        status.scrollTop = status.scrollHeight;
    };

    socket.onclose = function(event) {
        if (event.wasClean) {

        }
    };

    socket.onerror = function(event) {

    };

    document.forms["messages"].onsubmit = function(){
        let message = {
            msg:  ' ' + this.msg.value,
            from: this.from.value,
        };
        socket.send(JSON.stringify(message));
        return false;
    };

    socket.onmessage = function(event) {
        let message = JSON.parse(event.data);

        var hd = document.querySelector("#hidden_content");

        hd.innerHTML += `<div class="ui segment" style="min-height: 40px; word-break: break-all; min-width: 80%;">New message from ${message.username}</div>`;

    };
}

korozya
  • 17
  • 6
  • You must set this URL "echo.websocket.org" as proxy path in apache. When request come to that URL, apache do proxy to your WebSocket port and address. https://stackoverflow.com/questions/27526281/websockets-and-apache-proxy-how-to-configure-mod-proxy-wstunnel – Ramin Rezazadeh Nov 20 '19 at 15:31
  • @RaminRezazadeh is this right? apache can't start with it :( https://pastebin.com/raw/29suiy8e – korozya Nov 20 '19 at 16:16
  • Do you write these configs into virtual host tag? – Ramin Rezazadeh Nov 21 '19 at 06:18

0 Answers0