I'm running through the StreamHub hello world example from the online article Getting Started with Reverse Ajax and Comet. I think I've configured everything exactly as the article instructs, but I'm getting a JavaScript exception at new StreamHub().connect(..)
Here's my HTML file:
<html>
<head>
<title>Hello World Comet Application</title>
<script type="text/javascript" src="streamhub-min.js"></script>
</head>
<body>
<h1>Hello World Comet Application</h1>
<input type="button" value="say hello" onclick="start()">
<div id="streamingData"></div>
<script>
function topicUpdated(sTopic, oData) {
var newDiv = document.createElement("DIV");
newDiv.innerHTML = "Update for topic '" + sTopic
+ "' Response: '" + oData.Response + "'";
document.getElementById("streamingData").appendChild(newDiv);
}
function start() {
var hub = new StreamHub();
hub.connect("http://localhost:7878/");
hub.subscribe("HelloWorld", topicUpdated);
}
</script>
</body>
</html>
The line where the exception is being thrown is:
hub.connect("http://localhost:7878/");
It happens each time I click the "say hello" button, and the exception I'm getting is:
Invalid url for WebSocket ws://localhost:7878ws/
My browser is Chrome 11.0.696.28 beta, but I'm also having a similar problem on IE7, so I don't think it's browser开发者_如何学Python-related. It's kind of strange URI, isn't it? ws://localhost:7878ws/
What am I doing wrong?
I got the answer on the StreamHub blog. Apparently the tutorial in their earlier blog post is out of date. Here's what needs to be done:
If you migrate any existing Ajax SDK apps from 2.0.x to 2.1 or 2.2 you will need to change your connection URLs to incorporate the new streamhub context. For example, if previously you were using:
hub.connect("http://localhost:7979/");
You will now need to use:"
hub.connect("http://localhost:7979/streamhub/");
After changing the connection string, everything worked just fine.
精彩评论