so I'm tried to put socket.io into my node server in order to make a messaging function for my app but having problem getting to function despite doing test app correct. Not sure where the problem is exactly?
server.js
var path = require('path');
var qs = require('querystring');
var async = require('async');
var bcrypt = require('bcryptjs');
var bodyParser = require('body-parser');
var colors = require('colors');
var cors = require('cors')
var fs = require('fs');
var express = require('express');
var http = require('http');
var https = require('https');
var logger = require('morgan');
var jwt = require('jwt-simple');
var moment = require('moment');
var mongoose = require('mongoose');
var multer = require('multer');
var request = require('request');
var upload = multer({ dest: 'uploads/' });
var config = require('./config');
..
a bunch of code for mongoose
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
io.on('connection', function(socket){
console.log('a user connected');
});
..
ssl setup
// Create an HTTP service.
http.createServer(app).listen(8000); // opens the port
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(4433); // for the ssl
index.html
..bunch of code like bootstrap and angular.js
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.1/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost:8000');
socket.on('connect', function(data) {
socket.emit('join', 'Hello World from client');
});
</script>
so when I tried to run the site on localhost:8000. In the console, it send back GET /socket.io/?EIO=3&transport=polling&t=LnM0Fd3 404. I'm not sure what went wrong with the set up process of socket.io
via Jason Tran
No comments:
Post a Comment