我剛剛閱讀了關於web套接字並編寫了這個簡單的客戶端Java腳本。但即使我在Chrome瀏覽器上運行,它也不會給我任何輸出,我不知道什麼是FAULT? 可能是google.com不支持Web套接字?運行Web Socket客戶端編程
<!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>
請幫助..
感謝
斯納
1.同源政策可能是問題的一部分。 2.不,據我所知,Google不會在google.com上使用網絡套接字。 3.在google.com之前增加':'。 – Ryan