node.js - Deploy socket.io app into a domain ? -


i'm new here. starting socket.io , node.js, , tried upload project subfolder on domain, can't find subdirectories , socket.io (i saw questions, didn't work me) thie domain "http://www.nicolasrivero.com/2" it's working on localhost. here code...

the console log error this

http://nicolasrivero.com/socket.io/?eio=3&transport=polling&t=1429923179530-0 failed load resource: server responded status of 404 (not found) 

i think it's obvius, socket.io trying connect nicolasrivero.com , not nicolasrivero.com/2 ... appreciated (sorry bad english, lol)

index.html (head)

<script src="/socket.io/socket.io.js"></script> 

index.html (body)

<input autofocus id="name" placeholder="nombre">  <textarea  placeholder="caja de texto" id="area" style="width:220px; height:200px; background-color:white;  font-family: "times new roman", georgia, serif;"></textarea>  <input autofocus id="msj" placeholder="input name" onkeydown="if (event.keycode == 13) document.getelementbyid('enviar').click()" >          <button id="enviar" type="button" onclick="enviarmsj()"> enviar </button>     

index.html (js)

<script>       var socket = io.connect();      document.getelementbyid('area').disabled = true;     document.getelementbyid('msj').focus();       function enviarmsj(){          input = document.getelementbyid('msj').value;         nombre = document.getelementbyid('name').value;         console.log(input);         socket.emit('mimensajeenviado', input, nombre);         document.getelementbyid('msj').value = "";      }   socket.on('mensajeenviado', function(input, nombre){          console.log(input);         document.getelementbyid("area").innerhtml = document.getelementbyid("area").innerhtml + nombre + ": " + input + "\n";   });  </script> 

aaaand in server.js

var serverport = 3000; var http = require('http').createserver(myserver); var fs = require('fs'); var io = require('socket.io').listen(http); var nsight=0;  var contenttypes={     ".html":"text/html",     ".css":"text/css",     ".js":"application/javascript",     ".png":"image/png",     ".jpg":"image/jpeg",     ".ico":"image/x-icon",     ".m4a":"audio/mp4",     ".oga":"audio/ogg" }; http.listen(3000);  function myserver(request,response){ var filepath = '.' + request.url; if (filepath == './')     filepath = './index.html';  var extname = filepath.substr(filepath.lastindexof('.')); var contenttype = contenttypes[extname]; if(!contenttype)     contenttype = 'application/octet-stream'; //console.log((new date()) + ' serving ' + filepath + ' ' + contenttype);  fs.exists(filepath, function(exists){     if(exists){         fs.readfile(filepath, function(error, content){             if(error){                 response.writehead(500, { 'content-type': 'text/html' });                 response.end('<h1>500 internal server error</h1>');             }             else{                 response.writehead(200, { 'content-type': contenttype });                 response.end(content, 'utf-8');             }         });     }     else{         response.writehead(404, { 'content-type': 'text/html' });         response.end('<h1>404 not found</h1>');     } }); }   io.sockets.on('connection', function(socket){      socket.player = nsight++;         console.log(socket.id + ' connected player ' + socket.player);          socket.on('mimensajeenviado', function(input, nombre){        io.sockets.emit("mensajeenviado", input, nombre);   })  socket.on('disconnect', function(){      console.log('player' + socket.player + ' disconnected.');  }); }); 

socket.io connects server, not specific path. there no such thing connecting http://www.nicolasrivero.com/2. socket.io connects server.

fyi, url using http://nicolasrivero.com/socket.io/?eio=3&transport=polling&t=1429923179530-0 looks normal socket.io url. websocket connections start http request , type of http request socket.io registers handler in order field requests websocket connections.

if request returning 404, either because web server not running correctly or because socket.io not initialized correctly web server. can see if web server operating correctly checking other routes on web server see if working or not or putting debug info in http request handler.

when socket.io initialized correctly, configures handler in web server /socket.io route , handles incoming requests target route.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -