i have issue when using node.js socket.io ! can any one help me?
when any user connect with my node server connection event fire and emit
an event which handle by some browser windows and some windows never
receive means if. i connect 4 windows with my server than event may fire
in just 1 on 2 windows. after so many tries (Refresh) it effect in all of
windows i have check my application using chrome, firefox and IE
client
<html>
<head>
<title>Index page</title>
<script src="http://localhost:2000/socket.io/socket.io.js">
</script>
<script type="text/javascript" charset="utf-8">
socket = io.connect('http://localhost:2000');
socket.on('entrance', function (data)
{
document.write('<p>' + data.message + '</p>');
});
socket.on('oentrance', function (data)
{
document.write('<p>' + data.message + '</p>');
});
</script>
</head>
<body>
<H1>Heading</h1>
<form action="javascript:submit()">
<div id="show_text"></div>
<input type="text" name="text" id="text" />
<input type="submit" />
</form>
</body>
</html>
Server
var connect = require("connect");
var iosocket=require("socket.io");
var app=connect().use(connect.static(__dirname+"/public")).listen(2000);
var socket=iosocket.listen(app);
socket.sockets.on("connection",function(clientSocket){
socket.sockets.emit("entrance",{"message":"i am connected"});
});
socket.sockets.on("message",function(data){
console.log(data.message);
});
No comments:
Post a Comment