node.js - Node JS Socket.io -
i have been struggling around have socket.io npm module setup , browser able interface end nodejs script. not sure going wrong. remeber seeing messages in console that:
"socket.io .. started .."
but nothing happens now. below nodejs code:
var express = require('express'); var server = require('http').createserver(express); var path = require('path'); var favicon = require('static-favicon'); var logger = require('morgan'); var cookieparser = require('cookie-parser'); var bodyparser = require('body-parser'); global.socket = require('socket.io')(server); //global.socket = require('socket.io').listen(80, {log:true}); //socket.listen(80, {log:true});
in index.js file have function catches socket.io incoming connections. when try below url browser:
http://localhost:3000/socket.io/socket.io.js
i error message:
error: failed lookup view "error" in views directory "c:\amr\public" @ function.app.render
but when request below url:
http://localhost/socket.io/socket.io.js
it seems socket.io.js file rendered on browser:
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.io=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){
i not sure how browser or backend side can see if web socket working, script url have include in html page such connection works?
<script src="http://localhost:80/socket.io/socket.io.js"></script>
you may not have exposed socket.io client-side library public. if used express generator, copy , paste file yourproject/public
, send requests localhost:3000/<insert socket.io clientside filename>
if didn't use express generator, make folder called public, , in main project file place line app.use(express.static(__dirname + '/public'));
, described above
oh, , error there refers view engine not being able find view error printing. fix , it'll give more info.
Comments
Post a Comment