How are WebSockets used in an html file?

1

I did this function on an esy.es server:

<script>
net=new WebSocket("ws://tatopatato.esy.es/chat12.htm")
</script>

And I get an error:

  

Firefox can not establish a connection to the server at ws: //tatopatato.esy.es/chat12.htm.

Something similar happens in chrome, also if I put this:

<body bgcolor="black">
<script>
name=prompt("Enter your name, please.")
net=new WebSocket('ws://html5rocks.websocket.org/echo')
net.onmessage=function(){e.data}
net.onconnect=function(){net.send(console.log("User: "+name+" has connected"))}
onkeydown=function(){net.send(console.log(prompt("Enter your message.")))}
</script>
</body>

It's funny, because when I send a message it does not respond. What do I do to make it work?

    
asked by Cristein 14.10.2016 в 16:10
source

1 answer

2

You have to connect to a WS server. No to an HTML file. link

    
answered by 15.10.2016 в 00:59