运行Web Socket客户端编程 [英] Running Web Socket Client side programming
问题描述
我刚刚阅读了关于Web套接字并编写了这个简单的客户端java脚本。但是即使我在Chrome浏览器上运行而且我不知道什么是FAULT,它也没有给我任何输出?
可能google.com不支持Web套接字?
I just read about web sockets and written this simple client side java script. But it doesn't give me any output even if I run on Chrome browser and I don't know what is the FAULT?? May be google.com doesn't support Web sockets??
<!DOCTYPE html>
<html>
<head>
<title>Web socket Experiment</title>
<script type="text/javascript">
function callWebSocket() {
var socket = new WebSocket("ws://www.google.com");
socket.onopen = function () {
alert("Hello, Connected To WS server");
};
socket.onmessage = function (e) {
alert("The message received is : " + e.data);
};
socket.onerror = function (e) {
alert("An error occured while connecting... " + e.data);
};
socket.onclose = function () {
alert("hello.. The coonection has been clsoed");
};
}
</script>
</head>
<body>
<input type="button" value="Open Connecton" onclcik="callWebSocket()" />
</body>
</html>
请帮助..
谢谢< br>
Sneha
Thanks
Sneha
推荐答案
你错误 onclcik
在你的输入按钮。除此之外,你的代码应该可以正常工作,除非他在评论中提到minitech,我不认为谷歌目前有一个网络套接字脚本设置供你使用。尝试制作自己的服务器端脚本以指向或搜索现有的第三方网站示例(例如,快速谷歌搜索,我找到了ws://echo.websocket.org,我尝试了你的代码,它工作,除了错字)
you typoed onclcik
in your input button. Other than that, your code should work fine, except as minitech mentioned in his comment, I don't think google currently has a web socket script setup for you to use. Try making your own server-side script to point to, or search for an existing 3rd party site example to play with (eg, quick google search and I found ws://echo.websocket.org which i tried your code on and it worked, other than the typo)
这篇关于运行Web Socket客户端编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!