I want to create a basic chat application using web socket in JavaScript. I searched a lot about it on various search engines but I didn't found anything that could help me.
I am using Wamp server and don't have NODE.js installed.
- Can I create an application on Wamp?
- How to write a server code for Web Sockets?
Note: I am aware of Client code for web socket but don't from where to start with server code? The code I need can be in PHP or JavaScript. Below is a basic client code written by Me.
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
function WebSocketTest()
{
if ("WebSocket" in window)
{
alert("WebSocket is supported by your Browser!");
// Let us open a web socket
var ws = new WebSocket("ws://localhost:9998/echo");
ws.onopen = function()
{
// Web Socket is connected, send data using send()
ws.send("Message to send");
alert("Message is sent...");
};
ws.onmessage = function (evt)
{
var received_msg = evt.data;
alert("Message is received...");
};
ws.onclose = function()
{
// websocket is closed.
alert("Connection is closed...");
};
}
else
{
// The browser doesn't support WebSocket
alert("WebSocket NOT supported by your Browser!");
}
}
</script>
</head>
<body>
<div id="sse">
<a href="javascript:WebSocketTest()">Run WebSocket</a>
</div>
</body>
</html>