I have created nodeJS io.socket chat app using the link here -
http://cestfait.ch/content/chat-webapp-nodejs
I am able to run it on my laptop. I did not find any help on google how to connect to nodeJS app from other machines. I have another laptop which I have connected through wifi.
Now I really want to know how can I connect another user from another laptop to the nodeJS server running on my first laptop.
I will be very grateful for your help. Any help in broader sense will also be ok.
EDIT 1:
When I am trying Brandon's method, I am getting following error. Not sure what is wrong. I have to run the file client.html directly in the browser. Running http://192.168.43.244:8000/client.html throws the error.
C:\node>node server.js
info - socket.io started
C:\node\node_modules\socket.io\lib\manager.js:0
(function (exports, require, module, __filename, __dirname) { /*!
^
RangeError: Maximum call stack size exceeded
It's complicated.
If you don't have a static IP address (and you probably don't) that means every time you reconnect your computer to the internet, you are going to get a new IP address, so you'd have to update your code every time.
Also, there are issues with Firewalls, both on your dev machine and with (wifi) routers.
Best solution is to acquire a static IP. But its not cheap
First, make sure Socket.IO is connecting to the server serving the HTML. In client.html, change:
var socket = io.connect('http://localhost:8000');
to
var socket = io.connect();
Leaving out the host/port will cause Socket.IO to connect to the same host and port serving the HTML.
Once you've done that, you can access the server from another computer by visiting http://1.2.3.4:8000, where 1.2.3.4 is the IP address of the computer running the server. The connecting computer and the serving computer will need to be on the same network for this to work; if you want to (temporarily) connect with someone on a different network, you can use a tool like localtunnel.
Related
I am writing to ask what is causing the behavior of my NodeJS application. So, I am wanting to allow access to external connections to the server while running the application off of my computer.
NodeJS app.js
server.listen(3000, 'device-IPv4 address');
Then I am port forwarding off of my router on port 3000 just fine.
So when I access the server via http://device-IPv4:3000, things work perfectly fine as expected.
But when I access the server via http://PublicIP:3000, it technically loads, however, it often stalls by waiting for a connection giving the error:
"This site can't be reached. ERR_CONNECTION_TIMED_OUT."
But if it tries to connect enough times, it eventually loads seemingly randomly.
I would think that this set up would work just fine, so I cannot figure what would be causing that sort of behavior. What all could it be? If you need more info, just ask, and I can provide. Thank you for the help.
I'm trying to figure out the best workflow for producing an app I can have hosted on one of the various public Node environments. The sticking point seems to be that my app opens two ports: one for HTTP and another for WebSockets.
Here's the code which executes great on my own system, but runs into EADDRINUSE errors on hosted services. (NOTE: this is regardless of changes in port number)
CODE: http://pastebin.com/zjJKbj2U
QUESTION: Am I wrong in my approach of searching for a Node service that provides this ability, or should I be going about this in a different way?
Do you have a specific reason you think you need a different port for HTTP and web sockets? They are designed to work fine using the same port, and as you are seeing, things are much easier if you just use them that way. Your app can access both regular web resources as well as opening a web socket connection to the server at the same time over a single port. There's an example of using express for your web site and ws for websockets on the same port here.
So I'm getting into working with node.js and socket.io to make real-time web games, but I'm running into some obstacles.
I've already figured out how to install node.js and socket.io on my computer, and I can run basic servers and open them through http://localhost:8888/.
But now what I don't understand, and there doesn't seem to be anything on the web that explains this, is how to get this onto a website. Obviously, someone else on the internet that enters that same URL isn't going to see the same thing as what's on my screen. How do I get this onto a webpage so that anyone that visits that URL accesses the server?
I tried opening the port and then using http://<my external IP>:8888 but that doesn't work. Some sources seem to say that I need to install something on the website, but I installed node.js on my computer through command prompt, so I don't understand how that would work on a website. I found instructions for Linux, but I'm running Windows.
What you need is a:
web server - to host your game. You can, for instance, rent an EC2 instance from Amazon and install there all software required (Node.js, database, ...) or go with PaaS (Platform as a Service) solution like Nodejitsu or Heroku where you'll be given Node.js out of the box.
domain - to register a human-readable name for your web serwer (like. www.my-game.com). Normally, once you get your server, it'll have some IP address assigned to it. Domain name is an alias for it, easier to type and remember. Similar to, as in your case, localhost is just an alias for an IP 127.0.0.1 (special address meaning local system).
Of course, another solution would be to host app on your local PC and set up your router to forward traffic from it's external IP to your PC (assuming your ISP assigned you public IP). But then you'll have to worry about your PC, router and internet link being always online. And it'd be way slower than when going with external, dedicated hosting.
I'm trying to use web sockets to connect from a Google Chrome browser on my phone to a server running node.js and socket.io.
Using the remote debugging tool in Google Chrome I get this error in the console
Failed to load resource http://localhost/socket.io/1/?t=1368744562638
This happens despite me specifying my internal LAN IP in code for the client like so:
var socket = io.connect('http://192.168.1.3');
Furthermore it seems like the first heartbeat request makes it but starts to fail after that.
The code runs as expected when running the client on the server.
I am of course a idiot. I had another javascript file that had not been updated to connect to the specific IP I had set and was still set to "localhost".
After updating the host that socket.io should connect to in that javascript file everything is now running smoothly :)
I am just getting to grips with socket.IO and nodeJS. Got my web app working ok with them. I then got a friend to try it out at work on an office machine and found that it failed to connect.
I set up these two test cases:
http://thebeer.co/labs/rt/chat.php (server JS here) - This is an exact copy of the socket.IO chat example.
http://thebeer.co/labs/rt/test.php (server JS here)
Both of them fail for him. I also got a friend to try on a University computer and that too failed to connect! I've tried node servers listening on ports 8100, 8080, and 81-90 after being told that lower port numbers are less likely to be blocked by secure networks.
Really don't understand, it is very important that that real-time functionality is accessible to everyone, what am I doing wrong?
How can I get socket.IO to connect within secure Office and University networks?
A lot of big corporate networks will block everything other than port 80 (http) and port 443 (https) for most of their users. Try and put everything over one of those two for maximum compatibility.
Even when you get the everything running on port 80, also keep in mind that a lot enterprisey networks run HTTP traffic through content filters or other proxies that might not understand the websockets Upgrade header... you might want to try forcing socket.io to use one of the background compatibility transports and see if that helps.
FWIW, +1 to Colin Pickard because he is probably right... I just thought I would add this point just in case.
Take a look at both these links. I helped another so member who wanted the same.
I'm running nodejs on port 80 and I have no issues with corporate networks. (One thing I needed to have working as a priority)
How do I run Node.js on port 80?
https://serverfault.com/questions/273143/binding-apache-to-specific-ip-address/273181#273181