Can two java applications talk over javelin web sockets? - asynchronous

I'm developing a distributed Java application that implements state machines in a master -> slave/s configuration.
I would like the master to be able to communicate with each slave asynchronously. To my novice eye, Javelin Websockets looks like a nice lightweight solution to implementing SSL connections for it.
I'm currently struggling a little with it as all of the examples I've found so far are for Javascript in a web page talking to a server. Which isn't really what I'm trying to achieve. I want a persistent connection where each Java application can asynchronously send messages either way.
Before I end up wasting time I was wondering if anyone could tell me if what I want to do is possible, and if so, are they able to point me at any code examples that use a Java application on each end, rather than a web page talking to a backend?
Thanks for any help.
Brad

Yes, two Java applications can talk over Javalin WebSockets. From the perspective of a web server it doesn't matter if the WebSocket client is Java based or JavaScript/Browser based. Javalin itself uses https://github.com/TooTallNate/Java-WebSocket for WebSocket integration testing.

Related

easy server and client communication

I want to create a program for my desktop and an app for my android. Both of them will do the same, just on those different devices. They will be something like personal assistants, so I want to put a lot of data into them ( for example contacts, notes and a huge lot of other stuff). All of this data should be saved on a server (at least for the beginning I will use my own Ubuntu server at home).
For the android app I will obviously use java and the database on the server will be a MySQL database, because that's the database I have used for everything. The Windows program will most likely be written in of these languages: Java, C#c C++, as these are the languages I am able to use quite well.
Now to the problem/question: The server should have a good backend which will be communicating with the apps/programs and read/write data in the database, manage the users and all that stuff. But I am not sure how I should approach programming the backend and the "network communication" itself. I would really like to have some relatively easy way to send secured messages between server and clients, but I have no experience in that matter. I do have programming experience in general, but not with backend and network programming.
side notes:
I would like to "scale big". At first this system will only be used by me, but it may be opened to more people or even sold.
Also I would really like to a (partly) self programmed backend on the server, because I could very well use this for a lot of other stuff, like some automation features in my house, which will be implemented.
EDIT: I would like to be able to scale big. I don't need support for hundreds of people at the beginning ;)
You need to research Socket programming. They provide relatively easy, secured network communication. Essentially, you will create some sort of connection or socket listener on your server. The clients will create Sockets, initialize them to connect to a certain IP address and port number, and then connect. Once the server receives these connections, the server creates a Socket for that specific connection, and the two sockets can communicate back and forth.
If you want your server to be able to handle multiple clients, I suggest creating a new Thread every time the server receives a connection, and that Thread will be dedicated to that specific client connection. Having a multi-threaded server where each client has its own dedicated Thread is a good starting point for an efficient server.
Here are some good C# examples of Socket clients and servers: https://msdn.microsoft.com/en-us/library/w89fhyex(v=vs.110).aspx
As a side note, you can also write Android apps in C# with Xamarin. If you did your desktop program and Android app both in C#, you'd be able to write most of the code once and share it between the two apps easily.
I suggest you start learning socket programming by creating very simple client and server applications in order to grasp how they will be communicating in your larger project. Once you can grasp the communication procedures well enough, start designing your larger project.
But I am not sure how I should approach programming the backend and
the "network communication" itself.
Traditionally, a server for your case would be a web server exposing REST API (JSON). All clients need to do http requests and render/parse JSON. REST API is mapped to database calls and exposes some data model. If it was in Java, it would be Jetty web server, Jackson Json parser.
I would really like to have some relatively easy way to send secured
messages between server and clients,
Sending HTTP requests probably the easiest way to communicate with a service. Having it secured is a matter of enabling HTTPS on the server side and implementing some user access authentication and action authorization. Enabling HTTPS with Jetty for Java will require few lines of code. Authentication is usually done via OAuth2 technique, and authorization could be based on ACL. You may go beyond of this and enable encryption of data at rest and employ other practices.
I would like to "scale big". At first this system will only be used by
me, but it may be opened to more people or even sold.
I would like to be able to scale big. I don't need support for
hundreds of people at the beginning
I anticipate scalability can become the main challenge. Depending on how far you want to scale, you may need to go to distributed (Big Data) databases and distributed serving and messaging layers.
Also I would really like to a (partly) self programmed backend on the
server, because I could very well use this for a lot of other stuff,
like some automation features in my house, which will be implemented.
I am not sure what you mean self-programmed. Usually a backend encapsulates some application specific business logic.
It could be a piece of logic between your database and http transport layer.
In more complicated scenario your logic can be put into asynchronous service behind the backend, so the service can do it's job without blocking clients' requests.
And in the most (probably) complicated scenario your backend may do machine learning (for example, if you would like you software stack to learn your home-being habits and automate house accordingly to your expectations without actually coding this automation)
but I have no experience in that matter. I do have programming
experience in general, but not with backend and network programming.
If you can code, writing a backend is not very hard problem. There are a lot of resources. However, you would need time (or money) to learn and to do it, what may distract you from the development of your applications or you may enjoy it.
The alternative to in-house developed of a backend could be a Backend-as-a-Service (BaaS) in cloud or on premises. There are number of product in this market. BaaS will allow you to eliminate the development of the backend entirely (or close to this). At minimum it should do:
REST API to data storage with configurable data model,
security,
scalability,
custom business-logic
Disclaimer: I am a member of webintrinsics.io team, which is a Backend-as-a-Service. Check our website and contact if you need to, we will be able to work with you and help you either with BaaS or with guiding you towards some useful resources.
Good luck with your work!

What are the basic requirements for using WebSockets serverside?

I'm trying to learn about WebSocket as I see many possibilities with it and would like to explore it, but I am having a hard time understanding the basic requirements for it.
There exist a ton of blogs out there praising WebSocket like was it God and they explain how to develop WebSocket applications brilliantly.
However I don't understand when they all shortly mention that you need a WebSocket compatible server and then none of them tells you how to set it up and what you need to do to make it work properly when you call it through your client side scripts etc. - Even WebSocket.org fails to explain it.
Can anyone point me in the right direction?
Say I have an ASP.NET website and would like to use WebSocket to push notifications, maybe even have a chatroom. What would I need to do to make my Javascript-based chatroom application working?
If you are using ASP.NET, you will need IIS8 to work with WebSockets integrated in the app (so you would need Windows 8 or Windows 2012). Or, you can have a WebSocket server in another port/server.
If your "push" requirements are not very exigent, you can try SignalR: http://www.asp.net/signalr. Check out their tutorials to get started. But again, you won't be able of using WebSockets unless you are using IIS8.
Other WebSocket frameworks are XSocket.NET and SuperWebSocket. Or if you want you can take a look at my WebSocketListener that I am developing, that is just a lightweight WebSocket connector and nothing more, although it is under heavy development at the moment.
From client side, the WebSocket API is the same for all browsers.
Your question is very broad and not any particular problem specific.
WS (WebSockets) is protocol that is implemented in most modern browsers and platforms, and is well consistent.
But same way as you need something to be as HTTP web server (ASP.Net + IIS, Apache + PHP, node.js, python, etc) you need similar or compatible technology for WebSockets. As it is different protocol, your technology have to support. From "recognising" traffic as WS, directing to right process via socket/proxying, handshaking, deserializing traffic into actual data, and providing you an interface to work with all of it.
So you need basically google: "%YOUR TECH/LANGUAGE% WebSockets". That will give you information on how to use WS on your platform.
You need to understand specifics that it is different protocol, so it might not be that "friendly" with some complicated infrastructure cases.
ASP.Net 4.5 do support WebSockets by default, just find documentation on how to use it in ASP.Net.
And this question would not be raised if you would try to do some experimentation and prototyping with WebSockets in first place.

What AMF Servers Support Remote Shared Objects?

Greetings. I'm planning on building a Flex based multiplayer game, and I'm researching what will be required for the server end. I have PHP experience, so I started looking at ZendAMF.
Now in this game, I'll need the concept of rooms, and real time updates to clients in those rooms, so it looks like I'll be using remote shared objects (correct, yes?). I'm not seeing where ZendAMF can support this.
So I found this page: http://arunbluebrain.wordpress.com/2009/03/04/flex-frameworks-httpcorlanorg/
It seems to indicate that ZendAMF isn't going to do what I want. WebORB for PHP seems to be the only PHP based solution that does messaging, but on that page it doesn't mention "real-time" next to it like the Java based ones below it do.
What should I be looking at for the server piece with my requirements? Do I need to make the jump to something like BlazeDS and try to pick up a bit of Java knowledge?
Thanks.
I'd highly reccommed flash media server if you have the cash.
I've had good expereince with it in the past
Both ZendAmf and weborb use http long pulling. Think of it as pinging to check for updates. If you really need TRUE realtime push notification then PHP will not be your answer due to it not having threads or long running processes. WebOrb has several servers in other languages along with BlazeDS, RubyAMF, PyAmf, and of course LCDS from adobe that allows for true messaging.
I think you already know the answer, but for other people looking into this as well:
All *AMF solutions use HTTP as transfer protocol and can't have permanent connection. AMF is sent encoded through HTTP and then it's closed.
When you want to use "real" real-time (RTMP,RTMPT), you have choices like:
opensource: Red5 (Java), BlazeDS (Java), FluorineFX (.NET)
commercial: Wowza Media Server (Java), WebORB (.NET and Java)

How to connect Adobe Air client side with Java VM Debug Interface?

I'd like to know if/how would it be possible to connect Adobe Air application to Java VM Debug Interface? I have some objects residing on server side and don't want to change the code there and server already allows to do remote debugging.
Here's the information about JPDA:
http://www.j2ee.me/j2se/1.3/docs/guide/jpda/architecture.html
Greatly appreciate for your advice in advance.
Be very careful about opening the remote debugging interface to the Internet. That could be a huge security problem.
Security considerations aside, only a single debugger process can attach to the JVM at the same time.
You should really look at some of the more regular remoting protocols, such as SOAP or REST over HTTP(S) to talk to your server. This is not more work (probably less) than trying to shoe-horn JPDA into something it was not meant to do.

submitting to and monitoring an unreliable webservice

I am building an ASP.NET website which will collect data from a user and submit it to a 3rd party webservice. The webservice is somewhat unreliable and for this reason there is a backup service.
If a call to the primary service fails (timeout or some other error) then I need to flip a bit in a static class which will trip the system to use the secondary service.
At this point, I need to start polling the primary service (with dummy data) to see if it is back up (at which point I will receive an OK code in return). At this point I need to flip the bit back so that the website starts using the primary service again.
I've had a read of this Should I use a Windows Service or an ASP.NET Background Thread? and I think that separating out the code into a Windows Service would be the cleanest method of performing the polling, but then how would I communicate with the web appication.
One thought I've had is to expose a webservice that the Windows Service could use to communicate into the webapp but this seems both messy and over-kill.
I'd appreciate your thoughts and experiences performing similar tasks.
Thanks
I think the Windows service is the way to go, definitely.
As for the communication between the service and your web site, the best answer depends on the size and scale of your solution. If you are building something that needs to be reliable, I'd suggest you implement some sort of queue between your ASP.NET site and your Windows service. You have a lot of options here too, depending on budget and ability: BizTalk, MSMQ, and SQL Server queues (SSIS). Alternatively if you are looking for something smaller scale, I'd recommend you just stick it into a database table somewhere.
I would avoid using files on the file system because you will encounter issues with file locks and multithreading. I would also avoid directly communicating with the service because you risk losing the in-memory queue if the service fails for any reason.
Edited to add:
If reliability isn't a concern here, you could use a WPF named-pipes hosted service for communication between your website and your Windows service. This avoids much of the overheads normally involved in classic Web Services and is surprisingly quick. The only down-side is that self-hosting a WPF service is tricky and can be difficult to keep the service up.

Resources