sorry to bother you, but I've been looking for answers and I couldn't find them anywhere... Well i'm a fresh dude in the field of javascript and node.js and here's my problem:
I've created an application based on the tutorial of socket.io - Here's the link to the completed project of their chat example. everything is working as it should, but I would really need to trigger somekind of a command while node server is running... command should be triggered via php script.
The command should trigger an emit event - so every client in our case would see a new message sent via php.
I saw couple of suggestions to do it from another server with php/using cURL. The problem is that I don't know how to fetch POST data sent from php to node.js server.
Any solution to command node with php is more than welcome and again i'm sorry to bother you :)
You can use a bridge to exchange data between NodeJS and PHP. You will need to implement a PHP server that exposes remote procedures and a NodeJS client that calls those remote procedures. You can send any data to the NodeJS application from PHP using these remote procedures.
Here are a few links to get you started:
http://bergie.iki.fi/blog/dnode-make_php_and_node-js_talk_to_each_other/
https://github.com/bergie/dnode-php
Related
I have to build a project that connects a Java application with a node.js server. I've already built the server part, it uses MySQL to store values and can process HTTP requests to return them in JSON format.
The Java app must be able to retrieve data from the server and then process it. The thing is, this application must be receiving information constantly from the server because it will be updating frequently.
Any hints on how to start or documentation you recommend to build this?
Thank you in advance.
I've gotten a task at University to create a website for teaching other students how to use python libraries (Scrapy, BS) for web scraping. I've already set up the frontend part with React and React Ace editor and now I'm trying to figure out how pass code that user entered to the script. Do I need to make my own server (api) or I can call the python script directly and pass all the code using ajax request?
What is the best approach?
What I want is to pass all the code that user entered in the online editor to the python script and then return the output of that script as a response to the initial request, so that I could check whether the result is correct.
my suggestion is to create a server with API (it's actually AJAX)
and then to run the Python code,
one good option us to create express app (Node.js HTTP server) and use python-shell see the first example with runString option.
you will need a server with node.js and python installed.
of course this only for a university task, in this option you run the code on your server, and it's a pretty big security issue.
I have made a simple password protected webpage that provides the link to another webpage when we enter the correct password but we can easily have the webadrress of other page by browsers "View Page Source" feature.So how we can overcome this?
The problem is that you are keeping your secret data on the client and client can easily reach it. So, the only posible way for you is to keep them on the server. But, as far as I understand you need help with server part. So here is small instruction with links to the documentation.
You will need:
Some backend that will take data from your users and returns some responce. I would suggest you to have a look into Node.Js as a platform with Express as a server. Benefit from this setup is that Node.Js uses JavaScript so you have not to learn additional language, and Express is a very simple server to use. Of course, if you want to learn some other languages - you can take C# with ASP.NET MVC framework, PHP or any other nice language.
Some page with form for user's credentials that will post data to your backend. Basic form behavior can be found here
And some code on server that will validate credentials from form and return new page with or without your secret.
That's it. May be it sound a bit scary but there are lots of guides and information your can google.
Hope this helps. Happy coding!
Btw, if you are lloking for the some ready code, I have Node.JS client/server example with TypeScript (JavaScript with type validation) here. All you need is git, hope you already have it, and Node.Js
Then just execute this commands on your console (bash, cmd, etc)
git clone https://github.com/Drag13/typescript-browserify-template
This will download code from remote server to your local machine
npm install
Installs project dependencies - like express server
npm run server
Starts the server
cd..
npm run client
Starts the client
Maybe you will find this helpfull.
I am building a java chatting web application.(Server and Client in one project)
follow is my condition
Springframework 4.2.3
JSP
Maven Project which converted from a Dynamic Web Project
Unable to use node.js
So User scenario in my head is
User enters some text and press Send
Ajax call to deliver messages to server
Server checks the users who are currently connected(from Session maybe)
Server calls other users script to append new message
I am quite confusing with step4. Is it possible that Java calls DOM event trigger?
How could a client get a new message event from server?
Thanks. :D
P.S.
These days majority of chatting servers are event-driven. Is it possible to build an event driven chatting server with Java?
Your solution is formed as if there is no WebSocket technology available to you. WebSocket is implemented to solve real time messaging issues. It pushes message to the destination.
But if to stick wih your method following is meaningful.
You need someplace to keep incoming messages such as database or session.setAttribute [bad idea]. Then use some ajax call loop on the clients machine to ask for a new incoming message from server.
Probably your server will slow down due to incoming flood of GET requests from multiple users.
to Your last question in post scriptum: yes, I use tomcat websocket api.jar in my projects. There is well written documentation on apache.org
As I mentioned, learn WebSocket if your users are not using old internet explorer browsers. There are bunch of tutorials on it...
when i use comet iframe i just send script tags from backend php file to front end and javascript is displaying it.
can someone explain briefly where a comet server comes up in the picture and how the communication will be between frontend (javascript), backend (php) and the comet server.
cause i read that if you are going to let a lot of users use your comet application it's better to have a comet server. but i dont quite understand the coupling between these parts.
use this link:
http://www.zeitoun.net/articles/comet_and_php/start
That is the best tutorial i could found, and takes 1 min to try;
in short:
( image from that tutorial )
index, can be html or php, creates a request, which php doesnt answer until there is data to send back, with chat, when someone sends you a message.
If you have many users chatting, i recommend using a java chat app
otherwise your server will load up with running php engines ( each unanswered request keeps a php engine alive, which is server capacity ).
http://streamhub.blogspot.com/2009/07/tutorial-building-comet-chat.html
this should help you out with that, but you do need java hosting :)
have fun
edit:
just read the other server part; sending requests to your own server can get messed because the timeout function may not work well, so the server crashes, an independant server timeouts the connection after a certain amount of time, no matter what.
I have a very simple example here that can get you started with comet. It covers compiling Nginx with the NHPM module and includes code for simple publisher/subscriber roles in jQuery, PHP, and Bash.
http://blog.jamieisaacs.com/2010/08/27/comet-with-nginx-and-jquery/
A working example (simple chat) can be found here:
http://cheetah.jamieisaacs.com/