Bom dia pessoal,
sou totalmente novato em node.js, então resolvi fazer alguns testes.
Tenho exemplo web socket com
socket.io, o html é servido a partir do
APACHE, com seguinte código:
-=-=-=-=-=-=- cliente -=-=-=-=-=-=-=
// Create a socket instance
socket = new WebSocket('ws://192.168.1.157:843');
// Open the socket
socket.onopen = function(event) {
console.log('Socket opened on client side',event);
// Listen for messages
socket.onmessage = function(event) {
console.log('Client received a message',event);
};
// Listen for socket closes
socket.onclose = function(event) {
console.log('Client notified socket has closed',event);
};
};
=-=-=-=-= server =-=-=-=-=-=-=
// Require HTTP module (to start server) and Socket.IO
var http = require('http'), io = require('
socket.io');
var server = http.createServer(function(req, res){
// Send HTML headers and message
res.writeHead(200,{ 'Content-Type': 'text/html' });
res.end('<h1>Hello Socket Lover!</h1>');
});
server.listen(843);
// Create a Socket.IO instance, passing it our server
var socket = io.listen(server);
// Add a connect listener
socket.on('connection', function(client){
// Create periodical which ends a message to the client every 5
seconds
var interval = setInterval(function() {
client.send('This is a message from the server! ' + new
Date().getTime());
},5000);
// Success! Now listen to messages to be received
client.on('message',function(event){
console.log('Received message from client!',event);
});
client.on('disconnect',function(){
clearInterval(interval);
console.log('Server has disconnected');
});
});
quando executo o cliente aparece somente isto "debug - destroying non-
socket.io upgrade", alguém teria alguma ideia?
Valeu!
José Júnior