Node.JS Not working on the internet - porting

i have the basic webserver hello world app for nodejs on windows and it works on localhost. But when i test it from the internet it cannot connect. I set up port forwarding in my netgear router. Am i missing a step here to make my nodejs server visible to the outside world?
Thanks.
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');

Make sure you listen on 0.0.0.0 instead of 127.0.0.1
127.0.0.1 is a private network visible only to your computer. 0.0.0.0listens to all interfaces, including both the private and public (as public as it can be behind a NAT).

Looks like you're binding the server to IP Address 127.0.0.1 which is localhost. If you want to access it elsewhere you'll need to set it to it's internet IP. Check out whatismyip.com and use that IP instead.

Just to make sure.
Your code should run like this.
var http = require('http');
const port = 1337;
const host = '0.0.0.0';
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(port, host);
console.log('Server running at http://${host}:${port}');

Related

Using Strophe + bosh always return AUTHFAIL status

I am using strophe.js and bosh to connect to my openfire server.
Here are my openfire server details:
XMPP Domain Name: subpm.localdomain
Bosh (http-bind) : http://subpm.localdomain:7070/http-bind/
ip: let say 120.12.2.1
I have used Adium and successfully connect via bosh. I have to mentioned the ip address instead of xmpp domain name. http://120.12.2.1:7070/http-bind/ and in jid i have also used the ip address.
But using strophe i am always getting AUTHFAIL status. I am using ip address just like Adium to connect.
Here is the code for the connection
var conn = new Strophe.Connection("http://120.12.2.1:7070/http-bind/");
conn.connect('bilkhan#120.12.2.1', 'password', function (status) {
if (status === Strophe.Status.CONNECTED) {
console.log("connected");
} else if (status === Strophe.Status.DISCONNECTED) {
console.log("disconnected");
}
});
Can anybody guide me in right direction. Thanks.

Frisby.js Error: tunneling socket could not be established

I am trying to test an REST API on my local machine using frisby.js . It throws the following error.
Error: tunneling socket could not be established.
The machine address is something like 'https://machine_name:8443'
It seems that you are behind a proxy. Then, to make your frisby test working, you need to apply proxy configuration as follows:
var frisby = require('frisby');
frisby.globalSetup({
request: {
proxy: 'http://xx.xx.xx.xx:yyyy' // Provide proxy info (host, port) here
}
});
frisby.create('Your spec description here')
.get('https://machine_name:8443')
.expectStatus(200)
.toss();
Note also that you are using HTTPS protocol. Then you may find useful my answer in this post in case you have problems with SSL certificates

C# agsxmpp Domain vs connectionserver

I need to establish a connection with the following data:
Protocol: XMPP
Username: <Your username>
Password: AIR_<Your LoL password>
Domain: pvp.net
Connection security: Use old-style SSL
Connect port: 5223
connection server: chat.euw1.lol.riotgames.com
I only managed to connect to a normal domain server in this form:
username#domain.com/resource
However, I need to add somehow the connectionserver (chat.euw1.lol.riotgames.com).
I really hope someone is familiar with agsXMPP and can help me!
Thanks in advance!
Alright I was just confused, maybe it was just too late for exploring new libs.
However, if someone stucks like me on connecting, here is a easy solution on how to test a login with this library:
XmppClientConnection xmpp = new XmppClientConnection("pvp.net");
xmpp.UseSSL = true;
xmpp.Port = 5223;
xmpp.ConnectServer = "chat.euw1.lol.riotgames.com";
xmpp.Open("username", "AIR_password");
xmpp.OnLogin += delegate(object o) { MessageBox.Show("logged in"); };

How to use node.js Context.IO behind a department proxy?

Here is my node.js code to use Context.IO in a RESTful way rather than IMAP.
var ContextIO = require('contextio');
var ctxioClient = new ContextIO.Client({
key: 'MY_KEY',
secret: 'MY SECRET'
});
ctxioClient.accounts().get(function(err, res) {
if (err) throw err;
console.log(res);
});
When I executed the above code on my dormitory computer, everything worked fine. However, when I executed the code on my office computer, which is behind a departmental proxy, the code simply timed out. My department provides both http and socks proxies for internet access. The question is how to set it up in node.js?
By the way, I also tried
socksify node code.js
It did not time out. Instead, it just did not response.

Can I set up socket.io chat on heroku?

I have a simple socket.io chat application which I've uploaded to one of the new Heroku 'cedar' stacks.
Now I almost have everything working but I've hit one stumbling block. On my localhost, I open a connection to the socket server from the client with:
// lots of HTML omitted
socket = new io.Socket('localhost', {port: 8888});
But on Heroku, I obviously must substitute something else in for these values.
I can get the port from the process object on the server like so:
port = process.env.PORT || 8888
and pass that to the view.
But what do I substitute for 'localhost'?
The correct way according the article on heroku is:
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
socket = new io.Socket();
This ensures that io.Socket won't try to use WebSockets.
I was able to get Socket.IO v0.8 to work on Heroku Cedar by doing the following:
Within the Express app (in CoffeeScript in my case):
app = express.createServer();
socket = require("socket.io")
...
io = socket.listen(app);
io.configure () ->
io.set("transports", ["xhr-polling"])
io.set("polling duration", 10)
io.sockets.on('connection', (socket) ->
socket.on('myaction', (data) ->
...
socket.emit('result', {myData: data})
### The port setting is needed by Heroku or your app won't start
port = process.env.PORT || 3000;
app.listen(port);
And within the front-facing Javascript of your application:
var socket = io.connect(window.location.hostname);
function sendSocketRequest() {
socket.emit('myaction', $("#some_field").val());
}
socket.on('result', function(data) {
console.log(data);
}
Helpful links:
Heroku Node help
Heroku Socket.IO help
This has now changed as of Oct 2013, heroku have added websocket support:
https://devcenter.heroku.com/articles/node-websockets
Use:
heroku labs:enable websockets
To enable websockets and dont forget to remove:
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
After trying every combination under the sun I finally just left it blank. Lo and behold that works perfectly. You don't even need the port.
socket = new io.Socket();
I was also having this problem on heroku. I was able to make it work using the hostname "myapp.herokuapp.com" (or simply window.location.hostname, to work both local and in production) and setting the port to 80. I'm using SocketIO 0.6.0.
Wouldn't you just put your actual hostname?
2011-06-25T21:41:31+00:00 heroku[router]: Error H13 (Connection closed without response) -> GET appxxxx.herokuapp.com/socket.io/1/websocket/4fd434d5caad5028b1af690599f4ca8e dyno=web.1 queue= wait= service= status=503 bytes=
Does this maybe mean the heroku router infront of the app is not configured to handle web socket traffic?
[update]
It would appear as of 6/22/2011 the answer is yes... heroku does not support socket.io see this post: http://blog.heroku.com/archives/2011/6/22/the_new_heroku_2_node_js_new_http_routing_capabilities/