Comet WEb server implementation - javascript

I recently asked one question :- Handle Web Server with multiple clients
I have gone through the basic techniques to implement comet server like streamhub,Maven/Jetty etc.
I have following questions for that :
After that I found the issues like in case of Maven/Jetty internet
connection is required for downloading certain files from net.So it
it possible to implement it if no internet connection is there on
machine where the web server is hosted ?
Also I want the open source tools/technologies to achieve the thing
mentioned in the above question. and I think stream hub is not a
open source free version. Please help if you know any tool which is
free/open source to use.
Currently the web application is running on apache web server. so if
I use comet server what changes I need to do in that ??
Please help...
Thanks in advance...

For comet, pick a server which can handle many open connections. For a chat app I implemented which currently handles 10k open connections, I used Mochiweb. You might want to give that a look.
Going along the Mochiweb path, I will also recommend Erlang for implementing you server. It will be a small piece of code. Basically, you will listen on a path and hold the connection open till you have some data to respond with or timeout.
On the client side, you would write a simple JS function which will make an AJAX call and handle response timeout and data responses as and when they come. Nothing too different here. However, you may need JSONP instead (crossdomain/subdomain because of different servers for web and long poll), so ensure that your LongPoll server replies accordingly.

Related

Write PDF files from Web-App to USB-Stick

I am concerned with the feasibility of this:
On a pre-configured machine I will have a Web-Application pre-installed, next to an Apache-Suite. So client and server are the same!
In this Web-Application Users can drag and drop PDF-Files to an USB-Icon.
Then the Web-App should write the dropped PDF to an attached USB-Stick.
I have never done something like this (writing to USB), so I am fairly insecure.
And I am well aware of the browser-restrictions concerning JavaScript and Filesystem-Access, but...
after researching a bit I found out, that there might be some possible and
relevant (I'm a Web-Platform-Guy) solutions to this:
Make a "Chrome App" with USB-Permission (does this really work?)
Use PHP to find the USB and then write to it (how would that work under Windows?)
Use some Flash as middle man (not preferred)
Now I'd like to know:
Has anyone some good experience with before mentioned possibilities?
Has anybody ever done something similar? Did it work? Which path did you choose?
How would I know which drive the USB is mounted, and how would I get sure?
What other possible solutions to this problem are there?
You have a website ('client-side' user interface) and a back-end server ('server-side') running on the same machine. This gives you 2 options:
Client-side: Download a file through the browser via HTTP GET and let the user choose where they save it.
Server-side: Build your USB interactions into the back-end (Node.js) code, as #mcgraphix suggests.
Interacting with the USB on the server-side provides the most flexibility. Furthermore, there are a number of libraries that you can leverage. Head to npmjs.org and consider, among others, the following Node.js server-side packages:
usb-detection
usb
With the server-side approach, initiate a Webservice request when the user completes the drag & drop action on the client, and implement the USB interaction within the server (Express.js or similar) method which services the request.
If the letter of the stick is known then writing a file from PHP will be simple
file_put_contents( 'E:\\folder\\file.pdf', $data );
Update
You can read a list of drives into a dropdown and allow a user to select a default drive to write to
https://stackoverflow.com/a/8210132/696535
Your question is more an architecture question than a code specific question.
Your web app (if you insist on a web app) should have two major components, a server side component that can be given arbitrary commands, and a client side component (javascript using XMLHttpRequest) that can make requests to the server side component to execute said arbitrary commands.
So your server side component, the component that serves your web page should have some server side code that can write your pdf to the file system, it should probably generate the pdf file as well rather than doing that on the web browser.
Which technology you use is up to you, whether that's PHP, .Net, Node.js etc...
The general gist is you want a server side framework that deals with HTTP requests, in your case probably a post request from the client side containing the encoded pdf, and responds accordingly. Bind a particular http route to trigger your save logic.
Your http post request to the server will contain your payload which is the pdf file to a particular path, e.g. http://localhost/savepdf that whichever technology stack http listens to (you'll need to configure that)
Your server side component should read the incoming data, decode it as appropriate then make a file system request to write the received payload to disk.

Integrate Node.js with Symfony2 or PHP

I'm developing a web application with Symfony2. I need to create a push notifications sysmte (like Facebook). When an user publish something, I need some of another users receive a notification.
I saw that Node.js it's the easiest manner to do this. But, I did some simple examples and all works fine, but I don't know how can I integrate this node.js application with my Symfony2 application, or really with a PHP application.
Anybody can help me?
Thanks in advance!
Please note that you've not given enough details, so I will respond as a front-end developer and not as a mobile developer
Integrating NodeJS and PHP (in general) is not a good way since you need to launch both servers separatly, create the websocket server in JS while your application is in PHP and finally create a request (GET or POST) from your PHP to you JS server. Well, a big mess, so I'll expose my solution here under.
Quick insight for mobile apps. Well, technically, there's no easy way. You can use the Push "protocol" (http://www.wikiwand.com/en/Push_technology) with NotificationPusher (https://github.com/Ph3nol/NotificationPusher). I didn't used it before so I can't help you with it.
In general.
Most of the time when people thinks of Push, long polling will do the trick. For starters it means that the request is made client-side and the server don't send data & close connection until there's new data.
How do you implement this ?!?
Basically, you change the max_execution_time using ini_set or set_time_limit to a very long time for the current script and launch a loop (like a do..while) with a sleep and the check to your data inside. From your Javascript just make an Ajax call, for example with jquery: $.get. Just remember to remove the timeout and stay in asynchronous mode.
The only drawback of this solution is that you will always have a connection opened to your server which will consume a bit more of battery on a mobile device. If you have multiple types of data to receive do not hesitate to merge the calls and publish a type in your response data, since most of the browsers allows only 2 or 3 simultaneous connections to the same server.
I sounds like your describing WebSockets.
Take a look at Socket.io, its a module for node.js.
Also there is a example at GitHub https://github.com/Automattic/socket.io/tree/master/examples/chat
Interesting files for you should be the index.js and the public/main.js.
You can see the example live at http://socket.io/demos/chat/

send command via tcp ip through javascript

I want to achieve following functionality and need the help for the same:
I have one server on which there is device connected that prints some bar codes based on pre-formatted command given to it.
Currently there is one desktop application which generates the command and does the job.
Now I want to do this via web, meaning there will be one webpage (say .aspx) and I want to achieve this by javascript.
I am able to generate the pre-formatted command required for printing but I don't know how to send the command to server, whether socket tcp ip or something else.
I have tried using node.js, socket.io, json-socket etc. but nothing is working,
If javascript is a fixed requirement, then no I don't think you'll find a direct solution. You will need to create an intermediary service that will translate websocket protocol to the tcp/ip protocol your software communicates on. I found a package called Websockify that has implementations of this kind of bridge in a few different languages.
Although if you are open to using Flash on the front end, and can meet the security requirements on your backend connection, then Flash socket API could work. I believe Java applets can also manage this.
I don't believe this is possible to do from inside a web browser. If it were it would be a huge security vulnerability (think about it, you visit an attackers page and all of a sudden your printer starts printing and every shared directory on your network fills to the brim with junk data).
You could run the command on the server (node/.net/anything else...) and have the web platform talk to the server to kick the process off. But that sounds kind of like what you already have set up...
Alternately, if you can change the software on the connected device you could try to give it an HTTP endpoint which responds to POSTs.

how to build multi-user video chatting web app using webRTC, node.js and socket.io

im trying to make a web app that supports multi-user video chatting. ive read an article about webrtc on "getting started with webrtc"
(http://www.html5rocks.com/en/tutorials/webrtc/basics/) and done some demo on codelab. but i still dont really know how to make it a 3-way conferencing call.i dont really know a lot about node.js and socket.io. just started learning them because im trying to build this video web app.
so my question is which part of webrtc or socket.io determines that more than 2 users can join the call? or any resource that you guys get direct me to?
thanks in advance.
WebRTC is peer-to-peer protocol(browser-to-browser) without server,So you must know about my browser i must know about your browser means(your browser codec,public ip,port,etc) then only we can able to communicate,so we are using signalling(socket.io:web socket two way communication protocol send some information about my browser ,and receive some information about you browser ,with nodeJS server then peer connection will establish)
Three user communication is also possible in WebRTC using mesh network,see you send some information to me (browser information) at a same time you send this same information to other peer,when i receive some information about your i will send some information about me to you and other peer,the same thing will happen in other peer also.
Here some detail about mesh network http://en.wikipedia.org/wiki/Mesh_networking
I would say that there are two separate things here. WebRTC needs signaling to setup the peer-to-peer communication between two nodes. I think you are on the right track when using Node.js and Socket.js for this.
But it is not WebRTC (or socket.io) that decides if a third part can join the meeting, it is you that decides this. And this is the other part of the signaling that have little to do with WebRTC.
This meens that you implement functionality like setting up meetingroom, discover available meetingrooms, joining meetingrooms etc. When the three part meeting is up and running, each node will have two peer connections, one to each of the other nodes.
For N users, you need to use a media streamer like Kurento (http://www.kurento.org/)
Then you can build your own multi users webrtc solution such as: https://webrtc-chat.com/ (built on top of Kurento)
I looked at those protocols as well, not sure what node.js and sockets.io can do yet, but I think its a big mistake whatever they are doing, because all you need to do is create one place where multiple users will put their webcam images and then everybody could access the place separately to view all conversations. This has to be quick though because not a problem with video but if signal is slow then its not going to be understandable. I would try something else. I am wondering why they could not solve such an easy concept of multi-conferencing.
I have created a parody of multi-chat on my website, I cannot show you right now, but basically I save frames every 5 seconds of video and then store them (overwrite) the image saved in central folder. When somebody logs in they see all the webcams online (done with PHP). I don't know if this helps but it works and it is similar.

Javascript TCP connection to server

I have created server daemon, that produces some data, like messages and so. But, what im interested in - client monitoring. For example i have web page, and i need to establish persistent Tcp connection to server and show all incoming data into textbox. I know it can be done with flash, but im searching for JS implementation.
Is it possible and what`s the best practices ?
What you're asking for is known as Comet. Plenty of server software and client libraries exist - see the linked Wikipedia page.
WebSockets is designed to solve this problem.

Categories

Resources