Realizing real time Collaborative GUI with Java? - java

I wanted to create a real time collaborative GUI , as far as my knowledge is concern, i thought java swing MVC roots can play some role in that and can provide the basis. Am i right? i wanted to have experts reviews.
Which network technology/library will be suitable for this purpose and could give the high level support?
example usecase: If one client press the button or move the slider every client's button or slider move etc same for other swing elements?
Please share your ideas if you think something is achievable and can work as an small example or proof-of-concept.
Jibbylala

You likely won't find any out of the box solution to do exactly what you want, but you should be able to leverage existing technologies to do this. If you have a central server, you could use that to coordinate the clients. When one client does something, it could send a message to the server, which would then broadcast out to the other clients (the client could register with the server receive these notifications). If you don't have/want a central server, you could use UDP broadcasting, and clients could broadcast out their activities, and the other clients could listen and synchronize themselves.
Another challenge will be coming up with a messaging protocol to indicate what has changed. Do you envision needing every UI action to be broadcast (i.e. every button press, every component movement, etc), or will it just be a subset of them. If it is all of them, you might want to come up with a generic solution, like set property X on component Y, etc.
Hope this helps.

Related

Android Java listener for variable on Spring Boot server change

Hello I am wondering if this is possible to notify Android with some kind of listener the best via Retrofit when variable on server side change (to be specific concrete record on database shows up)?
Or you have any other ideas how can I achieve that with the simplest way.
The use case is that: I am developing Android RPG game. There are players that can fight with each other. They are all located on world map and you can choose the player you want to fight with. And now I want to get information in code once I am attacked or inform another player that he is attacked and open a new arena map dedicated for PvP fighting.
Currently I do it by retrofit call to server that checks if that record in database exists every few seconds but I guess it is not the best solution, as some people can have various internet limitations.
Kind regards.
Check out web sockets. They behave as you need.

Dynamically and in real time update web page contents

I need to create a screen that is automatically updated every minute or so with fresh data from a server-based data source, perhaps a simple text file or XML - and is displayed as a web page.
The screen will show a list of items that can be marked with a red, yellow or green icon, as to indicate their status. Each item has a drop-down where you can select/change the current status. So, when a user changes the status for one of the items, every screen monitoring this web page will be automatically updated.
I'm a pretty novice web programmer (I only have experience with desktop programming, VB and a little C#), so I'm really just hoping for a quick push in the right direction here. I assume that this really isn't all that difficult to implement. Am I wrong? And where can I find more info on how to do this? :-)
I really appreciate any help I can get. Thanks in advance!
This sounds like a solution with Websockets. You don't need update every minute. You're able to update every times when a user make changes. Client Side in Java Script is very easily to implement Websockets. Tutorial can be found here.
Server side you need a Websocket Server. What you need depends on which programm language you use.

Can Java read what is happening in an Adobe Flash based game?

Quite simply as the title states, is it possible for Java to read what is happening in a web-browser based Flash game?
For Example: Could I make a Java program which could play FarmVille for me by reading what is going on currently and make decisions based on a pre-determined set of actions?
FarmVille doesn't publish any sort of API, and you won't be able to access the RAM allocated to the Flash player (to my knowledge), so your only real course of action is to analyze the screen and automate input. In other words, there's no prewritten farmville.getUnplowedCells() to use, but you can write a program that takes screenshots, analyzes them to find the unplowed cells, and then generates the mouse/keyboard input that would make your character plow his unplowed cells. The Robot class can be used for this sort of programming.
This would be very time consuming and probably not worth the effort. Also as a side effect this would essentially "take control" of your mouse and keyboard and prevent you from using your computer normally. However this problem can be mitigated by running the program in a virtual machine.
No, there is no implementation for a Java-Flash bridge that allows anything more direct than IPC. Your best bet is decompilation (which would probably require deobfuscation) of the swf and interaction through common IPC mechanisms.
You could also tackle this using a different approach by recognizing elements on the screen by their pixel colors, for that you could use the Java Robot API which provides you with access to the keyboard, mouse and video. Since FarmVille is a 2D game, recognizing elements on the screen should be fairly straightforward -- performing image comparison, or partial image comparison (just the image's borders or a representative part) to increase the speed.
Aside, cheating in online games is not a nice thing to do and you can probably find activities that are more productive given you are smart enough to make software that works.
If you goal is to make a bot for FarmVille, then you're heading a wrong way. Keep in mind: it's ONLINE game. So, you don't have to read flash client's state, it'll be much more better, to read incoming packets, you don't have to simulate mouse/keyboard events in swf - just create correct packets, discribing your in-game actions. So I recomend you act like this:
1) Write a sniffer in Java (it's quite easy, because you have to write a simple one, not an ultimate tool, like Wireshark).
2) Use request's analytic (such as Firefox's Firebug) to catch some packets from your game. Reading them, you can retrieve all info, what you need: packets headers, game actions encoding, etc.
3) Code logic in your Java program: read incoming game packets and execute actions, sending requests.
4) Set user-agent options of your connection object similar to a popular browser (if you refuse doing that, game server may ignore your requests).
That's all. Remember: a game bot isn't an image recognizer, it's just another game client, with another GUI and logic.
P.S. If I misunderstood you, and your goal is to create a webpage with flash and applet, which comunicate with each other, you have to use JavaScript as a mediator between them. Flash calls JS using ExternalInterface.call, JS calls applet and vice versa.

Need some guidance with multi-app IPC

All I’m really looking for here is a little guidance. I’m trying to create my first official android app. I’m new to java/droid but not programming. Over the past month I’ve created quite a number of little experimental activities, services, threads and whatnot and they all function as planned. So now I’m trying to tie is all together but not having much luck.
In a new project I’ve compiled the guts into 'my.main.package' which runs a service that is constantly crunching data that other clients/apps can use… Well that’s my plan. For example, in this service is a custom thread/loop timer that is constantly counting. What would be the best way for any other apps to get a constant feed of this timer and other data as a listener could within its own sandbox and in the least taxing way possible?
I’m assuming one must implement aidl for IPC but I’m not sure if its needed and/or necessary as data from my.main.package is only outgoing, i.e. other apps only need receive/listen. I understand there needs to be some form of message handling or parcelable marshalling going on and possible permissions with aidl but I got to thinking that encoding/decoding a parcel or sending a message every millisecond would be very taxing. Is aidl the only way to go or is there a way to broadcast data as you can intent?
Any help would be greatly appreciated!
In a new project I’ve compiled the guts into 'my.main.package' which runs a service that is constantly crunching data that other clients/apps can use
A service should only be running when it is actively delivering value to the user. Users think that developers who create services that run all of the time are idiots and attack their apps with task killers, force-stops from the Settings app, etc.
Perhaps your description is just depicting your app in a poor light, but "a service that is constantly crunching data" is an anti-pattern. These are phones and tablets, not servers.
What would be the best way for any other apps to get a constant feed of this timer and other data as a listener could within its own sandbox and in the least taxing way possible?
The best way is for them not to be separate apps in the first place.
For example, in this service is a custom thread/loop timer that is constantly counting.
This is not adding value to the user.
I’m assuming one must implement aidl for IPC but I’m not sure if its needed and/or necessary as data from my.main.package is only outgoing, i.e. other apps only need receive/listen.
A remote service using AIDL is one way of doing IPC. It is not the only way. It is not even the most common way. You can also:
send a broadcast Intent
have the client send a Messenger to the service, and the service sends messages to the client via that Messenger
have the service update a ContentProvider, and have clients register a ContentObserver on the ContentProvider
I understand there needs to be some form of message handling or parcelable marshalling going on and possible permissions with aidl but I got to thinking that encoding/decoding a parcel or sending a message every millisecond would be very taxing.
IPC is "very taxing" in general. Hence, IPC should be avoided wherever possible.
In fact, IPC with AIDL is the only & the most effective way to do your requirements, I think. If you need one demo, you can take a look here. It's a simple example I wrote to learn AIDL & Binder on Android. Hope it could give you some brief for starting.

How do I write my own desktop sharing application in java?

Hello I want write my own desktop sharing application in Java.
The application should have some very default features:
Capture screen;
Allow a remote connected user to click / edit fields.
I was thinking to use Java Robot class for mouse movements / key pressing.
The problem is i don't know what screen capture strategy to use.
Should I make sequentially screen captures (on the hosting computer) every second, and send those captures with UDP via network, so that the clients can intercept the data-grams ? Isn't this a little overkill for the network ?
What other strategies are available ? (Except trying an already existing app).
PS: If necessary I can even write native code using JNI (still that's the last thing I planning to do).
Later edit:
After some investigation I've come to the conclusion of #Thorbjørn Ravn Andersen . Java is probably not the best choice for this kind of application. I can try to use JNI, but that code will cover 75%+ of my project.
I will try to find other alternatives.
Have a good long look at the Ultra VNC project on SourceForge. Great place to start.
In pure Java you cannot access structured information on system windows, nor monitor all relevant system events, so the performance of the display synchronization will not be optimal. Also there are privileged windows, which do not accept mouse or key events from Robot. Remote video streaming is not an option!
With named restrictions your attempt with the Robot class is valid.
Robot.createScreenCapture(Rectangle) will put a Desktop section into a BufferedImage, which you can send to the client window.
On client side you can capture keyboard and mouse events and send them to a Robot object on the server side.
Without knowing the actual extent of system windows, it will makes sense to work on a grid of Desktop tiles:
captured BufferedImage-s of tiles may fit into the buffer of the transfer protocol.
capturing period may locally be optimized for tiles with high entropy (-> Capturing Strategy).
Further traffic minimization
Consider differences of subsequent Desktop contents, only
Compression of tiles by PNG or a PCX-like method
For sharing over internet, Peer-to-Peer connection may be established by
a public proxy server
UDP hole punching with, for connection establishing, a necessarily public mediator server
In any case the protocol needs to be secured and delivery asserted.

Categories