Using WebSockets with Codename One - java

I am new at using Codename One. I am trying to deploy a server that will interact with my app on Amazon Web Services using OpsWorks. The server is going to run on Apache Tomcat and be a dynamic web project written in Java, and I am wondering the best way to communicate with the Codename One client. I am planning to use the Socket classes provided by Codename One, but and not sure what to use for the server-side code. Will it work to use WebSockets from Apache? I am having difficulty debugging the server code and have hit a wall here. Thanks in advance!

WebSockets aren't compatible with sockets so you will need to code a websocket implementation which is a bit of work. I suggest you use HTTP communication which is more portable and very performant on the devices.
You can also use solutions such as PubNub which allow for fast message based communications.

Related

Connect with iOS and Android clients to SockJS Backend

I'm developing WebSocket messaging backend using Spring WebSockets, which uses SockJS + STOMP protocol. The reason why not to use plain WebSockets is because I will need to leverage security integration that SockJS provides in Spring WebSockets and also other neat features from SockJS, such as rooms, subscriptions, etc. I was wondering if this is a good option to use so that mobile (iOS and Android) and Web client apps can easily connect to the backend server and perform messaging. If yes, then what libraries I can use for iOS and Android.
On SockJS GitHub page they are also listing available client libraries, but no iOS nor Android. So, I'm wondering if SockJS is even worth to use just because of that.
I found that for iOS client Primus-Objc (GitHub page) library claiming that they can connect to native WebSockets, Socket.IO, SockJS or perhaps engine.io. is that a true statement? And event if that's true, what about the quality of that library?
And event if it is ok to use SockJS on the back, then would it be also possible to show an example code for iOS and Android so that I can perform a proof of concept on mobile devices?
If SockJS is not a good option for me, then would it be better than to build my messaging app with Socket.io + Node.js (using JavaScript). Socket.io seems to me have all needed client libraries for iOS (official library by Socket.IO guys) and Android (official library by Socket.IO guys).
Another option can be to use Netty-Socket.io library and build each endpoint manually without any help from Spring Framework (which I'm considering to use) but there is small challenge that I'll have to tackle, that is security. Somebody actually already tried to do it (the same author asking question on the official Netty-Socket.IO Github page) but looks like he didn't have a luck in solving it yet.
Maybe it's more than a year since the question was asked. But, because it's getting in the first results when Googling for SockJS+Android. So, I am posting my answer.
From my experience with a recent project I worked on, we were able to use a STOMP client - like the one here- to connect to Spring Websocket backend from native Android app.
And from the browser, you can still use SockJS client to gain across browsers compatibility to websockets with fallback.
A note to mention that when using only STOMP client to connect to native websocket the URL will be something like ws://mydomain/SockJSEndpoint/websocket,
and when using SockJS client from the browser the URL will be like http://mydomain/SockJSEndpoint.
Please find below useful references related to your requirement for both iOS and Android
http://www.elabs.se/blog/66-using-websockets-in-native-ios-and-android-apps
https://www.cometchat.com/blog/ios-android-chat-mobile-sdk/
https://github.com/elabs/mobile-websocket-example
We have tested them, both Android-client (link) was given by #Amr K. Ismail and
this iOS-client (link) are suitable with Spring-SockJS-Server which has STOMP.
SockJS may be interesting because it provides non-ws transports. Just using WebSockets may not be possible in all situations.
There is one cross-platform SockJs client of the OpenFL project:
https://github.com/jeremyfa/openfl-sockjs
Not tested how well it works, but at least for Android it's using JavaScript from inside WebView, so should be no different than JavaScript one. Again, it is not clear how tightly it is coupled with OpenFL, but the approach of using WebView and stock SockJS client could probably be re-used.

Connecting Android and java EE server

I am making a game. The client runs in android. It is multiplayer and I want to check as much logic as possible on the server. I am interested how to connect the android client to the pure-java backend. I dont want to deal with the pure sockets as long as it creates a lot of programming overhead. Something like EJB would be perfect, but as long as can see, there is no rmi package in Android or anything. So the only way is connecting it throught Sockets or URL-objects to the REST-service (Could connect with URL to SOAP-based service - but its too complicated to do by hand). Serialization does not work between android and java. What is the best way to connect an Android app in a multiplayer game to the server (better java EE EJB`s or something)? Is there a way except pure XML?
You can use JAX-RS to build a RESTful Webservice, and you can use JSON as the payload. Jersey is a reference implementation, and is a good one. There is JSON support as well.

communication between jruby app and java app that are on different servers

Anyone has expirience on having Jruby project running on Jboss (using torquebox or whatever) with an ability to communicate with another "japps" not on the same jboss where jruby app is, i.e. some java project on another jboss?
I know there is an torque-messanging but dunno if it's possible to communicate with external(out of jruby-app's jboss) app?
Best practices are welcomed.
Thanks in advance.
P.S. placing that other app on the jboss where jruby app is not acceptible solution.
I can recommend you to use Thrift and build communication via them.
Thrift have generator for both your needed languages (Java and JRuby) and provide good and fast communication.
UPDATED:
Thrift is RPC (remote procedure call) framework developed at Facebook. In detail you can read about it in Wiki.
In few word to save you time, what it is and how to use it:
You describe you data structures and service interface in .thrift file(files). And generate from this file all needed source files(with all need serialization) for one or few languages(what you need). Than you can simple create server and client in few lines
Using it inside client will be looks like you just use simple class.
With Thrift you can use what protocol and transport used.
In most cases uses Binary or Compact protocol via Blocked or Not-blocked transport. So network communication will be light and fast + with fast serialization.
SOAP(based on XML on HTTP) packages, its in few times bigger, and inappropriate for sending binary data, but not only this. Also XML-serialization is very slow. So with SOAP you receive big overhead. Also with soap you need to write (or use third-party) lib for calling server(tiny network layer), thrift already made it for you.
SMTP and basically JMS is inappropriate for realtime and question-answer communication.
I mean if you need just to put some message in queue and someone sometime give this message and process it — you can (and should) use JMS or any other MQ services(Thrift can do this to, but MQ architecture is better for this issue).
But if you need realtime query-answer calls, you should use RPC, as protocol it can be HTTP(REST, SOAP), binary(Thrift, ProtoBuf, JDBC, etc) or any other.
Thrift (and ProtoBuf) provide framework for generate client and server, so it incapsulate you from low level issues.
P.S:
I made some example in past https://github.com/imysak/using-thrift (communication via Thrift Java server + Java Client or node.js client), maybe it will be useful for someone . But you can found more simple and better examples.
Torquebox supports JMS. The gem you specified torquebox-messaging allows for publishing and processing of HornetQ messages on the local JBoss AS server/cluster that the JRuby app is running in. I don't think it currently supports connecting to remote servers.
Using this functionality in your JRuby app you could then configure your Java app on another server to communicate with HornetQ running in the JBoss AS that the JRuby app is running on.
Alternatively you could always implement your own communication protocol or use another Java library - you have access to anything Java you want to run from JRuby.
You can use Web Services or JMS for that

Best way to manage asynchronous / push communication with web clients on a Spring based Java server

I need to push events to web clients in a cross-browser manner (iPhone, iPad, Android, IE/FF/Chrome/etc.) from a Spring based Java server. I am using backbone.js on the client side.
To my best knowledge, I can either go with a Web socket only approach, or I can use something like socket.io.
What is the best practice for this issue, and which platform/frameworks should I use?
Thanks
Looks like you're interested in an AJAX Push engine. ICEPush (same group that makes ICEFaces) provides these capabilities, and works with a variety of server- and client-side frameworks. There is also APE.
You can have a look at Lightstreamer.
My company is currently using it to push real time financial data from a web server.
I suppose Grizzly or Netty may fit your needs. Don't have a real experience in that scope, unfortunately.
I'd recommend socket.io as you mentioned in your question, if you're doing browser based eventing from a remote host. Socket.io handles all the connection keep-alives and reconnections directly from javascript and has facilities for channeling messages to specific sessions (users). The real advantage comes from the two-way communication of WebSockets without all the boilerplate code of maintaining the connection.
You will need to do some digging for a java implementation thoughConsider running the server directly from V8.

Communicating between Java and Flash without a Flash-specific server

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.

Categories

Resources