<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>hi</title>
</head>
<body>
<div id="conn"> This : </div>
<input type="text" id="text">
<input type="button" value="Button" onclick="func()" id="btn">
<script>
var fees=document.getElementById("conn");
var btn=document.getElementById("btn");
var conn = new WebSocket('ws://localhost:8080');
function func()
{
var text=document.getElementById("text").value;
conn.send(text);
conn.send('any msg');
text.innerHTML+= text+'<br/>';
}
conn.onopen = function(e) {
console.log("Connection established!");
};
conn.onmessage = function(e) {
console.log(e.data);
fees.innerHTML+= e.data+'<br/>';
};
</script>
</body>
</html>
This my code for running websocket. i am using ratchet websockets and xampp server. Main problem is the onmessage is not firing ! (I don't know why).
Console shows that connection established!. No more errors on console. Please help ... thanks in advance.
I have successfully implemented Socket.io websockets.
I think it is easier to implement that Ratchet websocket