WebSocket connection to 'wss://localhost:12345/' failed
import websockets
import pathlib
import ssl
import asyncio
import json
import logging
print('LIVE')
klient = []
me = []
dop = []
async def send_message(message: str):
for i in klient:
await i.send(message)
async def new_client_connected(client_socket: websockets.WebSocketClientProtocol, path: str):
print("New client connected!")
klient.append(client_socket)
new_message = await client_socket.recv()
await send_message(message=new_message)
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
# Generate with Lets Encrypt, chown to current user and 400 permissions
ssl_cert = "sertificat.pem"
ssl_key = "key.pem"
ssl_context.load_cert_chain(ssl_cert, keyfile=ssl_key)
print(ssl_context)
async def start_server():
await websockets.serve(new_client_connected, 'localhost', 12345, ssl=ssl_context)
if __name__ == "__main__":
event_loop = asyncio.get_event_loop()
event_loop.run_until_complete(start_server())
event_loop.run_forever()
document.addEventListener('DOMContentLoaded', function(){
let websocket = new WebSocket("wss://localhost:12345");
websocketClient.onopen = () => {
console.log('Client connected');
sendMessageButton.onclick = () =>{
websocketClient.send(messageInput.value);
messageInput.value = "";
};
};
}, false);
</>
document.addEventListener('DOMContentLoaded', function(){
const messagesContainer = document.querySelector("#messages_container");
const messageInput = document.querySelector("[name=message_input]");
const sendMessageButton = document.querySelector("[name=send_message_button]");
let websocket = new WebSocket("wss://212.113.133.150:8080");
websocket.onopen = () => {
console.log('Client connected');
sendMessageButton.onclick = () =>{
websocket.send(messageInput.value);
messageInput.value = "";
};
};
websocket.onmessage = (message) =>{
const newMessage = document.createElement('div');
newMessage.innerHTML = message.data;
messagesContainer.appendChild(newMessage);
};
}, false);
curl -v https://localhost:12345/
?curl -v https://localhost:12345/
выдает следущее:curl -v https://localhost:12345/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 12345 (#0)
* schannel: SSL/TLS connection with localhost port 12345 (step 1/3)
* schannel: checking server certificate revocation
* schannel: sending initial handshake data: sending 174 bytes...
* schannel: sent initial handshake data: sent 174 bytes
* schannel: SSL/TLS connection with localhost port 12345 (step 2/3)
* schannel: encrypted data got 1671
* schannel: encrypted data buffer: offset 1671 length 4096
* schannel: SNI or certificate check failed: SEC_E_WRONG_PRINCIPAL (0x80090322) - Главное конечное имя неверно.
* Closing connection 0
* schannel: shutting down SSL/TLS connection with localhost port 12345
* schannel: clear security context handle
curl: (35) schannel: SNI or certificate check failed: SEC_E_WRONG_PRINCIPAL (0x80090322) - Главное конечное имя неверно.