We are trying to play audio on the client machine. It is a web application based on Java EE, wherein due to some event happening at server side, the client should ring a bell or something of that sort.
I am not aware of any such thing. Alternative is to use
Html5
, but then it's become browser dependent that the browser should be Html5 compatible. I cannot enforce this requirement onto the client.
I went through
Red5
but found it not very useful..
Please advise
There are two parts to the problem:
playing sound in a browser
the browser being notified of events on the server
For playing sounds, and to support a wide range of browsers, you have a number of options. HTML5 <audio> tag and Plugins (Flash, Java applet). You could also use a Javascript library such as Yahoo Media Player to make this easier. A starter is here.
The second problem is how to notify clients when an event on the server occurs. This could be done with AJAX calls polling the server. Since you are using Java EE, this could be made a bit more efficient using Asynchronous Servlets. You could also go down the WebSocket path with this as well, though there can be issues through proxy servers with this.
Related
I want to develop a Java server that is able to send messages asynchronously to a client in form of a website with JavaScript. I know that one possibility is using WebSockets, but these are not supported in IE 9.
For transmitting messages from client to server I can use AJAX calls with maybe a RESTful Interface on the server side.
Does anyone have a solution for this?
This is not how webservers work, most of the time. HTTP Webservers are inherently a request-response architecture:
HTTP functions as a request-response protocol in the client-server computing model. A web browser, for example, may be the client and an application running on a computer hosting a web site may be the server. The client submits an HTTP request message to the server. The server, which provides resources such as HTML files and other content, or performs other functions on behalf of the client, returns a response message to the client.
That said, there are technologies that you can use to do this. Read here about Comet and Reverse AJAX:
Is there some way to PUSH data from web server to browser?
You better implement your Java server to act as a Websocket server when it's supported by the end user. For the users who does not support Websocket it should fall back to long-polling.
This behaviour will avoid unnecessary overheads due to long-polling communications whenever possible.
The good thing is you don't have to implement all these behavious from the scratch. You can readily embed and use a reliable implementation available open source.
One such implementation is CometD project. The CometD project was available for more than a decade and it has evolved to solve most of the issues.
If you are looking for commercial products, there are many available. One such would be lightstreamer (http://www.lightstreamer.com).
You need to use a design pattern like long polling since WebSockets is not available. Rather than build it yourself you could use a library like SignalR. SignalR is an ASP.NET library but there is a client for Java (https://github.com/SignalR/java-client)
For anyone who comes across this question more recently, the modern answer (as of early 2021) supported across all browsers (except IE, which even Microsoft has given up on in favour of Chromium-powered Edge) are server-sent events. A most elegant and standardised solution to providing a pub/sub model to web clients.
I am currently working on a point of sale application.
we have a existing system based on java which uses javapos to integrate with the devices (such as receipt printer, cash drawer , MSR etc).
now we are trying to port the java based thick client to service enable , so it is set to become a web app backed by html5 and spring webservice
my problem is to integrate the devices to the web ie browser so that the cashier can access the point of sale application from the browser .
how do i integrate the devices to the web app now. one option i have is deploying a java component in the register and make it communicate it to browser via websocket.
browser<-> websocket <-> java device component in local system
Is there any better way to do this? i need the technology which enable me to do the same.
i have considered the applet as well but the problem is the local java component is kinda huge and it will have different device drivers for each system.
JavaFX offers a pretty decent web browser component, that allows easy communication between the Javascript code that runs in the page and the Java code outside. You could port your application so that:
It uses JavaFX, openning a window with just a browser component and pointing it to your web application
Implement the web app as normal - it will display in the browser component
Move the device-specific Java code in the JavaFX app, expose its methods to the browser; now the Javascript code will call Java and (hopefully) you will be able to reuse most of your existing code, excluding UI code of course
A "Hybrid" JavaFX/HTML application example is iBreed (it is a framework that you can use actually).
I think you can make it work, but you will need one more piece of software.
Webserver (hosting the HTML-files and API)
Client PC (runnning the HTML-frontend in a browser) woth conected devices
new service running on the client PC, with a Web-API for the connected devices
I think, this is exactly the same approach as you mentioned with websockets. (Ony for older browser).
Take a look at atmosphere. This may help you to get the websocket stuff done:
https://github.com/Atmosphere/atmosphere
I need to create web application which must have two separate web browser windows to comfort usage. And events on each of them must cause action on another. The app will be on html5, perhaps with websockets on client side and Java with glassfish on server side. Is there any way to cross browser window communication or some another solution for this problem?
The best way to solve this problem is to store the information on the server side and have the web application communicate with the server (with JavaScript I expect).
You can have the web page "poll" the server every set period (eg 5 seconds) to see if there is an event or message to handle.
I used postMessage before - but not very heavily, worth a shot.
See post and demo at: http://robertnyman.com/2010/03/18/postmessage-in-html5-to-send-messages-between-windows-and-iframes/
Also see http://benalman.com/projects/jquery-postmessage-plugin/ for jQuery postMessage
Yes, I described a lot of ways here:
How is it possible to share single js resource between browser tabs?
If the browser support is not so important for you, then you can use shared webworkers. The next option to use storage event to exchange data, one implementation is intercom.js for that. The most supported way to use cookies BNC Connector does that.
Well, past few days I am trying to put plans for my chess server project on the table. It is planned to be made of several web services which interact mutualy. Web services are planned to be made with Java language and deployed onto Apache Tomcat 7.0.20 with Axis2 1.6.0 web service engine.
So far, there will be authentication web service, player pool web service, validation web service and 'bussiness logic' web service which will be only web service known to client application. All clients requests will be done through this service and forwarded respectively.
All players moves must go through web services because of move validation, history and so on. Problem occurs when other player needs to be informed of opponents played move. Persistant client request (to discover is opponent played move) towards service is out of question because player turn change must be immidiate when opponent play his move. How to achive this using java web services and eralier mentioned technologies? Is it possible to web service contacts opposed player and inform him about opponents move? Is there another way to do this with this scope of technologies?
Edit: Client application is planned to be desktop application, possibly Java or C#.
One option for Tomcat-to-web-browser push communication is Comet (sometimes called CometD or Bayeaux).
From the wiki article:
Comet is a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it.
(Note: Emphasis Mine)
What this means is that the server can notify the client of pending changes without the browser specifically polling. With a good JavaScript framework (such as Dojo or this jQuery plugin), you can seamlessly work with older browsers by polling.
Some good links for learning more about Comet:
RESTful Web Services and Comet
Comet Slideshow Example on Grizzly
Advanced IO and Tomcat
Dojo Foundation CometD
Hopefully this helps.
You do not state your client technology (browser? desktop app?)
Anyway, there is no direct solution if you are addressing home users. To work with home users, you would need them to open / NAT the needed port to their computer so you can access their PC. It is very complicated to the average home user.
For browser it is even more complicated as they are clients, not servers. Maybe some framework might be used to simulate a server inside a browser (I think there is at least one but I cannot recall its name), but that would work like just by repeating ajax calls to the server until a change is made.
And last, if you are checking the server every second, that would be a latency low enough even for "fast-chess".
I have Java and Flash client applications. What is the best way for the two to communicate without special Flash-specific servers such as BlazeDS or Red5? I am looking for a light client-only solution.
Well, you can make http requests from flash to any url... so if your java server has a point where it can listen to incoming requests and process XML or JSON, your flash client can just make the request to that url. BlazeDS and Red5 just aim to make it simpler by handling the translation for you making it possible to call the server-side functions transparently.
Are they running in a browser (applet and SWF), or are they standalone apps?
If they're running in a browser then you can use javascript. Both Flash and Java are can access javascript. It's fragile, but it works.
If they're running as actual applications then you can have Java open a socket connection on some port. Then Flash can connect to that and they can send XML data back and forth.
I've done both of these, so I know they both work. The javascript thing is fragile, but the socket stuff has worked great.
WebORB for Java may be of some help to you. It integrates with your J2EE code.
For more info:
http://www.themidnightcoders.com/weborb/java/
I'm sorry, I reread your question that you are only looking for a client side solution. In this case, WebORB will not help you. Sorry for the misunderstanding.
There's a Flash implementation of Caucho's Hessian web service protocol. This approach would be similar to using JSon or XML, but is more performant, since Hessian is a binary protocol. If you happen to be using Spring on your server, you can use the Spring/Hessian binding to call you Spring services directly from your Flash application with minimal work.
Merapi Bridge API
Merapi allows developers to connect Adobe AIR applications, written in Adobe Flex to Java applications running on the user's local computer.