1

I have installed python-mod-pywebsocket on my ubuntu system. I'm trying to test websocket. When I send and receive a message in the same html file, then it works fine, but when I'm doing that in different files, it doesn't work as expected. I'm pasting the codes below

Websocketsend.html

<!DOCTYPE HTML>
<html>
<script type="text/javascript">
function WebSocketTest()
{

    var ws = new WebSocket("ws://localhost:9998/echo");
ws.onopen = function(){ws.send("Hello!!!");
            alert("Message sent!!!");}; 
}
</script>
<body>
<button onclick="WebSocketTest()">Send</button>
</body>
</html>

websocketreceive.html

<!DOCTYPE HTML>
<html>
<body>
<script type="text/javascript">
var ws = new WebSocket("ws://localhost:9998/echo");
ws.onopen = function(){alert("Connection open");};
ws.onmessage = function(evt)
{
alert("Message received");
};
</script>
</body>
</html>

I've put these two files in my /var/www directory. I ran the socket server on port 9998 and then opened two different tabs in google chrome to urls localhost/websocketsend.html and localhost/websocketreceive.html respectively. In the first tab, it displays an alert box stating "Message sent", in the second tab, it shows an alert box saying "Connection open", but I can't see an alert box saying "Message received" in the second tab. Can anyone help me out?

I may be asking a very trivial or silly question, but I'm new to websockets and would appreciate any help.

Thanks in advance

rivarolle
  • 1,528
  • 11
  • 18
ndh
  • 331
  • 1
  • 4
  • 12

0 Answers0