我拥有域(例如:mydomain.com)
我想通过域连接到套接字
P.S。现在我正在连接到本地网络套接字var socket = new WebSocket("ws://localhost:8080");
如何将Web服务器和WebSocket保持在80端口上(因为它们冲突)?
如何使用域(如var socket = new WebSocket("ws://echo.websocket.org");
)建立与套接字的连接?
我读到有关Apache代理的信息...但是我不明白该怎么办...
我正在使用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>`;
};
}