Alright,I wrote a simple JavaScript websocket client code that connects to my C++ server.
- I am unable to get the message I send to the c++ server I only get the request and not the message.
- The message I send from my c++ server I do not get it on my browser console.
- The connection doesn't last the JavaScript websocket disconnects after about 1mins and when I use my c++ server to connect to another c++ client server the connection last forever until one disconnects and I'm able to send and receive messages.
Here's a sample of the request received from the JavaScript websocket
Host: 127.0.0.1:56000
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows
NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/105.0.0.0
Safari/537.36
Upgrade: websocket
Origin: http://127.0.0.1:5501
Sec-WebSocket-Version: 13
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Sec-WebSocket-Key:
GWwF9IG/Y4br7dalUK1xHQ==
Sec-WebSocket-Extensions:
permessage-deflate;
client_max_window_bits
Here is the simple JavaScript websocket client side.
<!DOCTYPE html>
<html>
<body>
<script>
var socket = new
WebSocket('ws://127.0.0.1:
56000');
//while(true){
socket.addEventListener('open',
() => {
console.log("we are Connected");
socket.send(JSONG.stringify
("hello"));
// socket.send("Hello Server!");
});
socket.addEventListener
('message', (event) => {
console.log('Message from server
', event.data);
});
//}
</script>
</body>
</html>
My Question is can't JavaScript send or receive messages from other languages pricisely C++ ?
I need assistance from anyone who understands.