Low Latency communication using web sockets & Java Server - java

I'm looking to establish a low latency 2way communication between a javascript interface (client) and a java server.
The client has to request data from the server (can ask for different set's of data, needs to be async, data are small sets of sensor data).
I was thinking of implementing this using websockets because of it's low latency. However I'm stuck at choosing a java websocket server implementation (I found jetty but there are so many, and there is also a case to be made for node.js and socket.io but there are not going to be a lot of clients in this case; just one client sending multiple requests so correct me if i'm wrong but there doesn't seem to be a reason for going the node.js path).
Last but not least; the server is running on a raspberry pi and is recieving it's sensor data over a special protocol; (but i don't think that's important for this question).
Is there anyone with some experience in this field and wants to share his/her toughts? Thx.

I've been using Kaazing (HTML5 edition) to proxy traffic received via a web-socket to a Java process listening on a traditional TCP server socket.
It's working well, latency is low and was consistently handling over 1000 messages/second (though we found our Java code was the limiting factor in that respect).
Kaazing also provides client APIs for Java, JavaScript and Flex, which allowed us to write an acceptance test suite using the familiar APIs (Concordion in my case).
I don't know how well it'd run on a Raspberry Pi, but given it's free to download there's a simple way to find out.

I've solved my problem by using Atmosphere which is a framework that provides compatibility to all major java servers and web browsers. (The Java Official Standard is still in the workings).
https://github.com/Atmosphere/atmosphere
I've got the chat demo up and running.

Related

EJb, direct ServerSocket or any other implementation

I am working on a Chatting Website project which will provide similar features as was like yahoo messenger with chat rooms...
Where multiple clients will connect to the central server and chatting(communication) and file sharing(if possible) will take place.
Now i did a bit of research and i came out with the following choices:
For the client i will use either Winforms or WPF with c#
And for server I am confused between,
Direct Servesocket based application to be deployed on a VPN or a dedicated server,
or EJB based something,
Or any other technology as you may suggest to be suitable for this.
kindly keep somethings in mind:
1. It should be scalable enough to be able to sustain 100 - 1000 to 1,00,000 clients
2. Server should also serve android app as client end.
3. Deployment details also requested

Using iOS iPad2 to Connect and Logon to Java Server Running HTTP Service

I am writing an iOS 5.1.1 app for the iPad2 using Xcode 4.4.1. I want to be able to locate a local http server running on Java.
Once I am able to connect to the http server, all I need to communicate with it is the url including the port.
My questions:
1) Should I use Bonjour or a DNS Server running on the http server to discover the http server itself?
2) I need to authenticate the iPad2 user with name and password to work with the http server once I discover it.
I need some help understanding how I would go about accomplishing these two steps including source code if available for the iOS 5 and Xcode 4.4.1.
1) Bonjour is pretty easy to tie in with Java apps. If you're particularly masochistic you can write your own Java-based mDNS (Bonjour) responders (I've done it, it's not rocket science), but the quickest way to get going is to use jMDNS in your http server to advertise its existence. I won't copy & paste the code samples but they suffice for most applications.
On the iOS side, NSNetService is your friend. Fundamentally it involves starting a responder in the background to look for services (i.e. your Java app), then calling a delegate when something appears/disappears:
id delegateObject; // Assume this exists.
NSNetServiceBrowser *serviceBrowser;
serviceBrowser = [[NSNetServiceBrowser alloc] init];
[serviceBrowser setDelegate:delegateObject];
[serviceBrowser searchForServicesOfType:#"_http._tcp" inDomain:#""];
There's a guide that explains it all. The protocol hasn't changed for 10+ years and you count on all modern iOS/OS X versions supporting it. The jMDNS library is pretty well battle-tested at this stage, too.
You might consider creating your own service type if you don't want it to be visible to other apps that search for _http._tcp., although this is just a cosmetic thing.
2) The simplest thing that'd work would be HTTP basic auth; you didn't say what kind of authentication your app supports or how you make HTTP requests on the client side, but this is pretty well covered already.

Running java server application 24/7 and secrets behind all those famous online live apps

I'm currently building an application that is about VOIP / random chatting, which is similar to skype or chatroullet. My question is extension to this
https://stackoverflow.com/questions/11384155/running-java-server-application-24-7-not-on-local-machine
I've been experimenting and playing around with TCP / UDP sockets and now I have ability to build VOIP / instant chatting applications. But as you might already know, in order for data transmission between client to client or client to server, the server application has to be powered on (in other word, be online) and be accessible by client applications. The problem is that, I'm not living by my self but with my family, which I can't simply use one of my computer to run my server application for 24/7 mainly due to the electricity bills and my lack of knowledge about the networking concerns me about the security, because I had to go through some configuration / port forwarding on my current router in order to make the protocol accessible by other users outside of my local network. So my biggest question is that, how do people or developers normally have been dealing with this kind of situations? Have they been simply using their own computer to run the server application? or have they purchased an external machine to run the server application
===========================================
Additional question:
Is TCP / UDP socket the only way of making applications such as MMO, VOIP and instant chatting programs?
i see that your topic was closed in the previous thread. I think such questions are unrelated to stackoverflow.
However, i would like to give you a glimpse of what is happening to most of us who own / make Java Web Applications. I used to work in a datacenter for a year and a half. Java applications are a little harder to put online as they require resources that not many data centres are willing to invest time and support in. Other than that, they are pretty much as straightforward as normal PHP applications.
You will need the standard options like Colocation, Dedicated Server, VPS, Cloud Virtual Machine, or a shared tomcat / application server hosting.
Colocation is where you put your own purchased and configured server with the data center, you have complete ownership of the server, nobody can touch it unless permitted by yourself. You pay to put your server into the data center, and are in charged of anything that happens within the server, including OS patch.
Usually servers in data centers (due to size constraint) come in rack units. 1U refers to 1 rack space, usually this is equivalent to one PC, although a server is much more powerful. In Singapore, the charges per U is SG$200.
Dedicated server is where you lease a server from the data center. The server is managed by the data center and can be as powerful as you want it to be. OS updates, installations, service guarantees are provided by the data center.
VPS is having a fraction of a server resource, but many challenge that you do not have the "root" access to the server in most cases.
Cloud is the virtualization of the entire operating system. If this was Linux, you would have the root access to it. Many of us now are going for this option because of its scalability. Some data centers may use popular virtualization hypervisors like VMware ESXi, Microsoft Hyper V.
The list above is represented from the most expensive to the least. Of course, that is depending on your location and service provider.
Hardly anybody i know tries to put a running server at home, it is a fire hazard itself, you will not know when your electricity will be cut off, standard dedicated bandwidth would as expensive.
Hosting with a data center would be much cost efficient and safer in my opinion.
EDIT:
Is TCP / UDP socket the only way of making applications such as MMO, VOIP and instant chatting programs?
Have you looked at HTML 5 Web Sockets, or any AJAX based framework for this?
Try searching the web for cloud hosting. For example, Heroku, AWS and many others provide a hosted service. That is what people use to host their service and it is more cost effective than trying to maintain something yourself.
Are you writing an Android application for it as well? Just as an aside you might want to make use of this ARO tool to ensure you are using the network efficiently. http://developer.att.com/developer/legalAgreementPage.jsp?passedItemId=9700312

Android: Transfer file over TCP Java Socket

I am currently trying to transfer a file from a Android device to a Java TCP Server, but I am unable to find a good example which explains the structure I would need to implement this. There are many Java Client&Server examples there which explain file transfer but I want to make sure if this will still work once one throws an Android Device in there.
My question is how do I implement this sort of structure? And if it doesn't work, would I be better sending the file over an HTTP connection to a PHP server? I see a lot of examples and documentation online for the later method so I presume it is more reliable. I would however prefer to use a Java server.
The file consists of a large set of coordinates recorded by the Android device which will then be sent to the server. I have not yet established how I will store this data yet but I was originally going to store them in a primitive text file.
Design
The first thing you need is something to allow you to run Java code on your server.
There are a number of options. Two of the most popular technologies are Glassfish and Apache Tomcat.
Crudely speaking Apache Tomcat is sufficient for simple client-server communication and Glassfish is used if you need to do more complex stuff. Both allow Servlets (which are essentially self contained server classes written in Java) to run on the server-side.
They handle communication with the client by launching a JVM (Java Virtual Machine) each time they receive a request. The Java servlet can run inside the JVM and respond do some processing if required before sending a response back to the client.Each new request is run in a new instance of a servlet. This makes dealing with multiple concurrent requests simpler (no need for more complex threading).
Networking (sending data to and from the server)
In networking situations the client can be a PC, an Android phone, or any other device capable of connecting to the internet. As far as the server is concerned, if the client can communicate using HTTP (a standard protocol which it understands) the it doesn't care what sort of device it is. This means that solutions for PC desktop client-server applications are similar to one for a phone.
You can use library such as Apache HTTP Components to make it easier to handle HTTP requests and responses between the device and the server. Of course you could write your own classes to do this using Sockets but this would be very time consuming, particularly if you have never done it before.
Storage of Data
If you have time I would recommend implementing some sort of database to store the information.
They have a number of benefits to such as data recovery mechanisms, indexing for fast searching of data, ensure data integrity, better structuring of data and so on.
If you decide to use a database I recommend MySQL. It is a free and more importantly - well documented.
Aside: JDBC can be used to communicate with the database with Java.
Sorry about the in-line hyperlinks - apparently my repuation isn't high enough to post more than two!
Source: Personal experience from implementing a similar design.

Java game server with Android client

I'm about to start a game project. It will be a network game with client-server architecture with Java server and a Web and Android clients. Impact is on low bandwidth (for use on mobile devices) and fast response. What technologies / libraries are out there for client-server communication? I am somehow experienced in web applications (GWT/Vaadin and servlets) but have no clue what to use when implementing a game server, mainly for the communication.
I am aware that I could use Java sockets with Object serialization or maybe JSON to pass the data from client to server, but I don't know how efficient in terms of bandwidth these approaches are? Or are there any more suited than these? Just pointing me in the right direction will suffice.
Thanks in advance!
As far as Android client libraries go, there's two main options. The first is just the java.net.* package in which you'll mainly use HttpUrlConnection.
The better option is to use the Apache HTTP package that also comes standard in the Android SDK. It gives you a lot more control / flexibility / verbosity in dealing with network connections.
Here is a decent example of how to use the Apache client libraries. I suggest using these, as the java.net packages are really only suited for the most basic of GET requests.
I suggest using the JSON method, because then you're not stuck having to write a Java servlet backend to deserialize the Java objects. The backend can then change independently of the client.
The main problem is, if you use WebTechnologies, than you can't implement an efficient way to realize the communication from Server to Client ...
Client to Server over HTTP GET works fine, but you must use some kind of Comet to realise the communication from server to client.
Thats why plain old tcp connection over socket would may be the better to communicate with a Client, especially with Android Client.
But implementing it with tcp socket work great with android, but not with a Browser.
My solution: implement the communication via WebSocket.
WebSockets (part of HTML5) is a HTTP extension to enable full duplex communication between client and server.
The most major web browser support WebSocket, like Firefox 4, Chrome 9, Opera 10.7
BUT NOT the Internet Explorer (support planned in IE 10, comming with Windows 8)
And for android, there exists also java libaries to implement the communication and i would excpect, that they work also well with android.
Expample:
http://code.google.com/p/weberknecht/
For the server side: Servlet API 3.0 support that, like Jetty 8
In my opinion WebSocket would save the problem, so you can implement a single server which supports WebSocket and communicate via WebSocket to an Android client as well as with a Browser Client (except Internet Explorer)
It depends on timeframe of your project. If time is enough – try in your hands and compare the technologies related to your purposes.

Categories