'Localhost says upgrade required
I am working on a web rtc project. I have create four files: index.html, server.js, client.js and package.json. My server is node.js. When I input node server.js, it produces nothing. Then, when i write on my web browser localhost:8080, it says upgrade required. Any solution? Please. Thanks in advance.
Solution 1:[1]
This means that you have a http server listening on 8080 without websocket capabilities. Your webrtc client needs websocket to be able to talk with the server. You need also socket.io. Example:
// Require HTTP module (to start server) and Socket.IO
var http = require('http'), io = require('socket.io');
// Start the server at port 8080
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(8080);
// Create a Socket.IO instance, passing it our server
var socket = io.listen(server);
// Add a connect listener
socket.on('connection', function(client){
// 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');
});
});
Solution 2:[2]
This means that you have an http server listening on 8080 without WebSocket capabilities. Your webrtc client needs a WebSocket to be able to talk with the server. You need also socket.io. Example:
// Require HTTP module (to start server) and Socket.IO
var http = require('http'), io = require('socket.io');
// Start the server at port 8080
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(8080);
// Create a Socket.IO instance, passing it our server
var socket = io.listen(server);
// Add a connect listener
socket.on('connection', function(client){
// 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 dis
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Istvan |
Solution 2 | Jakub Kurdziel |