I just follow this from other site,I am still newbie in socket.io with node.js,.I am confuse why it did not echo in the console.can someone help me on this.
Thank you in advance.
app.js
var server = require("net").createServer();
var io = require("socket.io")(server);
var handleClient = function (socket) {
// we've got a client connection
socket.emit("tweet", {user: "nodesource", text: "Hello, world!"});
};
server.listen(8080);
io.on("connection", handleClient);
index.html
<html>
<head>
<script src="http://ift.tt/I1ZsPw"></script>
<script src="/http://ift.tt/1aeIZU4"></script>
<script>
$(function(){
var iosocket = io.connect("http://localhost");
iosocket.on("tweet", function(tweet) {
// todo: add the tweet as a DOM node
console.log("tweet from", tweet.username);
console.log("contents:", tweet.text);
});
});
</script>
</head>
<body>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire