this is my first node.js and socket.io application , i didn't use express ,I want to deploy the application on heroku do i need to use it ? i mean i just did npm install socket.io on localhost and in my server file i.e game.js i have io = require("socket.io") and socket = io.listen(Number(process.env.PORT)) only and in one of the files where from where i am sending the message i have socket = io.connect();
so please tell me if i need to use express and how show i modify my existing application ?
I have given the link to the source of application
( https://github.com/bitgeeky/herokutest )
Although the Application works fine on localhost by changing the port no , to some port no like (8000) but Heroku error log on doing "heroku open" is http://pastebin.com/MtB0z5vQ
I noticed that you haven't created a http server. I am assuming that you are creating a web application, since you are deploying to heroku. For that, you need to create a http server in nodejs.
Go through socket.io https://github.com/LearnBoost/socket.io
Also http://socket.io/#how-to-use
This should get you started
Note: You do not need express. But it will make your work easier in many ways. Depends on the type of application that you want to create.
Related
Hello I'm trying to deploy an express app that uses Socket.io for communication with the node server it's hosted on.
First problem : the server couldn't find the socket.io node module
somehow... even though it gets resolved on localhost.
We then switched to loading the socket.io client side through the socket.io cdn.
But we are getting this being spammed in the console :
Failed to load resource: the server responded with a status of 404
(Not Found)
https://pictionar-e.herokuapp.com/socket.io/?EIO=3&transport=polling&t=Lbg7iEM
From this error is looks like socket.io is trying to communicate over polling ? But I don't get why.. heroku supports websockets. Could https cause things not to work anymore?
Server side we've got the socketio/express server setup like this :
app=express();
server=require("http").Server(app);
server.listen(port,function () {
console.log("Server started at port: "+port);
});
io=require("socket.io")(server);
On localhost everything works fine but when on heroku the socket.io doesn't work, while the express server does its thing perfectly fine...
Note: we are using the port that gets assigned automatically by the heroku environment
I have a problem with socket.io#^1.0. The setup is fine because it works locally, the server is correctly configured and when i try to connect to the server from my Angular APP it works fine with this:
io.connect("localhost:8080");
The connection is established and i can send and receive event. Now in the production environment, "locahost:8080" is replaced with the address of the server Launched:
io.connect("https://domain-name.com/api");
I know that the problem here is the /api, since socket.io is considering it as a namespace and it's trying to connect to it, in my network console I see 500 Internal server error with the address https://domain-name.com without the /api when i replace the request url to add the /api I get a 200 OK with type octet-stream.
So the question here is: how do I connect to the correct path without consideration of the namespace?
Thanks in advance for any help :)
I think you want to use the path option (documented here):
// client
var socket = io.connect('https://domain-name.com/', {
path : '/api/socket.io'
});
I've set up a CoffeeScript with node.js application on a subdomain such as node.domain.com using a port 8901 (http://node.domain.com).
Within my coffeescript app, I'm using socket.io to communicate with the node server and client.
socket = io.connect('http://node.domain.com')
The problem is doing it that way, I've got an error :
GET http://node.domain.com/socket.io/1/?t=1437482662157 404 Not found
I would try including the port number in the initialization of socket io.
socket = io.connect('http://node.domain.com:8901)
I am building windows azure application which is primarily based on .NET, but I also have to build a socket.io server using node.js hence i need to deploy a socket.io server and use this socket.io url to connect in my .NET application.
I followed all the steps listed here . And I am able to get the socket.io running on my local but when i deploy to cloud, it doesnt start. Please find below a code snippet for socket.io
var app = require('express')()
, server = require('http').createServer(app)
, io = require('socket.io').listen(server, { origins: '*:*' });
server.listen(4001);
When i hosted it in my local emulator, 127.0.0.1:81 was pointing to this in my browser
But 127.0.0.1:4001 showed "Cannot GET /" on the browser, which is an indicative that the socket.io server is running on that url.
But when i deploy the same to cloud, i get the same as the screenshot on the url where the cloud service is hosted but on port 4001 where the socket.io server should have started it says page cannot be displayed.
Please let me know if you need to see any other files like web.config etc.
I have been stuck on this issue from forever and its really crucial for my project, any suggestions or ideas would be deeply appreciated.
Thanks
The important part that you are missing from the sample is setting of the port number
var port = process.env.port || 1337;
and
.listen(port)
when you are running inside of the Azure environment (even emulated) the ports are assigned for you, the port environment variable will tell you where. 4001 is likely not the assigned port.
The 1337 would only be used if you are running by executing
node server.js
from the command line
I'm noob on nodejs and i'm trying some tutorials of nodejs. I'm trying this tutorial: http://cestfait.ch/content/chat-webapp-nodejs it works wonderful on my localhost but not when I upload to appfog like you can see here: http://nodebruno.hp.af.cm/
For example, the prompt don't show up. I changed the code to avoid the prompt and insert the nickname on a input text and this work on localhost but doesn't work on appfog too.
I already tried on nodejitsu servers and I have the same problem
Can you help me ?
Your app has an error, it's trying to connect to a localhost socket.io server.
You need to change this line:
var socket = io.connect('http://localhost:8000');
to
var socket = io.connect();
And it would work preferably on Nodejitsu