Now I am learning node.js and created a simple chat server using node.js.
My code:
net = require('net');
var sockets = [];
var s = net.Server(function(socket) {
sockets.push(socket);
socket.on('data', function(d) {
for (var i = 0; i < sockets.length; i++) {
if(sockets[i] == socket) continue;
sockets[i].write(d);
}
});
socket.on('end', function() {
var i = sockets.indexOf(socket);
sockets.splice(i, 1);
});
});
s.listen(8000);
How can I share this chat server on the Internet, so other people can use it?
On my local machine, I have an access through telnet:
telnet localhost 8000
If you really want to let others use this chat through telnet over the internet (which I recommend against), you will need to forward a port through your router (I assume you use a router) to port 8000 on your local machine. Give your friends your IP address and the port you mapped, and they should be able to telnet in as well.
It's hard to answer this question without more information, however. Do you use a firewall? Modem? Etc.
Its really hard to answer this question based on all the information.
It all depends if you are behind a router, firewall etc. If you are directly connected to the internet through a modem you can use ipconfig(in command prompt) to find your public ip. If you are behind a network router you will most likely have to setup port forwarding. If this is the case, just do a Google search on your router, I'm sure you will find a tutorial to set it up or you can refer to your manual.
Here is a explanation on port forwarding: http://en.wikipedia.org/wiki/Port_forwarding
Hope this helps or points you in the right direction!