I have test node.js + socket.io with port 8080 yesterday
i found that the frontend page which receive the data and send request must defined as HTML
which mean, i can use a mvc php combine with node.js and socket.io
is there any way to do that?
more if i define the node server as localhost:8080
i cant call the web server by other place, such as localhost
unlike nature websocket, i can use the socket anywhere, and i just need to define the socket address as localhost:8080
anyway to solve out?
Run node on port 8080 run php on port 8081. Use php to run your frontend HTML and JavaScript include the frontend socket.io library and connect to localhost:8080 (the node server)
// client side code
var socket = io.connect('http://localhost:8080');
This is untested, and I don't know if this is what you want, or if it will work.
Related
I think so many people have previously searched for such question ..
Is it possible to do port forwarding with some PHP script on a normal hosting service ?
for example , use a local program to exchange data with server with normal GET / POST requests to a specific PHP page
and maybe a program on the other side (client) also a simple program to use this port forwarding method to send requests to the local server
or is there any idea similar to this ?
I'm developing a realtime chat app using node js, socket io which is embedded unto an php app. So basically, running my php app unto my local machine by...
php -S localhost:8000
and then the node server runs on port 3770 and yet, I was unable to connect to my node server. Tried...
var socket = io.connect('http://localhost:8000/my-php-app/:3770');
Seems, i put the wrong web socket url. Any help, ideas?
I am trying to develop a socket.io application. It is just a simple application like the one on the Getting Started - Chat application tutorial in the Socket.IO webpage. But the problem is that, I do not want to have the socket.io server serve the client automatically, because I am planning to have a page (in PHP) have a script that can simultaneously be updated by data from a server in real-time using Socket.IO. I just want a certain client that can connect to the server and let them communicate, not a page served by the socket.io server.
Is this possible? Can you please give an idea on how can it be done. Thanks.
That chat tutorial is just a simple deployment where your own web page wants to connect back to the same server that the web page came from. That is not the only way to do it.
The socket.io client code can be served from anywhere. You can even link to a CDN and get it from there instead of from your own server.
And, likewise, the client can connect to any compatible server as long as the server is configured to accept a connection from your page.
If you're looking for how to connect to a different server, you just specify the URL of the desired host in io.connect() like this:
var socket = io.connect('http://www.example.com');
I have a frontend application that need to call a reporting services, opening a new window with a javascript function like this :
window.open('http://somedomain.com:8080/report')
What I wanna do now is, since the tomcat server is on the same machine of the backend application(and on the same machine of the web server - php), avoid to open the 8080 port on the internet.
In simple words, I need a way to connect the tomcat application server(through localhost) and proxy the connection to the frontend without requiring to open the port 8080 of the server to the all world. Is it possible ?
How can it be done ?
To generate html page on the server I use php...
EDIT/UPDATE
The page on the tomcat application server is not static, it has a loading mechanism and need user interaction ...
You could use PHP's cURL functions to get the information you need via PHP (using localhost:8080) and use this as a PHP proxy. Then use Ajax to retrieve the information from the PHP proxy.
I'm trying to build a calendar with live update using Socket.IO Websocket. I managed to get the Socket.IO server running on port 8181 but my calendar.php is managed via apache on port 80.
What I'm looking to do is to use my calendar.php with apache and at the same time connect to my Socket.IO server on port 8181 (or bind it to port 80 with apache but that seem to be pretty complicated, I tried back proxy but didn't work) to receive updates when someone edited a event in the calendar. My events are stored in a SQL database.
So is there a way to use Socket.IO on port 8181 in a php page served by apache on port 80?
Thanks!
I'm not sure I understand your issue. Once the page is served by PHP on port 80, you would connect to your socket.io server on 8181 in the simplest set up.
And from then on you wouldn't need to interact with php again since you'd probably be sending messages to your socket.io server to process.
For load balancing socket.io, I think you can use HAProxy and I think LearnBoost has an alternative on Github also. I actually haven't gotten to this step with my app yet, so I can't give too much info here.
But yeah, your socket.io server should receive, process and send messages. You can also use redis for Pub/Sub if you have multiple instances of socket.io running.
There is a node module for an asynchronous MySQL driver that will allow you to interact with your Database directly. I'm using MongoDb in my app, so I've never used the MySQL modules.
I guess alternatively, you could use your PHP server as a web service and your socket.io server could interact with it, but I imagine it would be slow to do it like that.
Hopefully that clears things up. Seems like your set up will already work in a dev environment.