How to let a java program comunicate with a different java program - java

I am trying to build a system that loadbalances minecraft players across multiple servers and creates new minecraft servers. I made a plugin to loadbalance players and it works like a charm. But now I want to make a system that creates new servers based on the data it receives from the plugin.
This system is completely seperate from the plugin. But how do I make it so the plugin sends some sort of command to the server system so it knows to create a new server. I have looked into Sockets but was wondering if this is the best solution. Maybe a Rest api will work aswell?

In my opinion the best solution is sockets based on your own protocol, it will be much more productive, than http or something else.
I can suggest using this lightweight socket library written by me -
Sonder.
It's working directly on sockets using nio.

You could solve this by having one java program write to a .txt file and another program read the line then delete the command using java.io.FileWriter and java.util.Scanner. I have a github project that does this here:
https://github.com/DPS100/Diego-s-Project-Euler/blob/master/Main.java

Related

Can Electron apps be integrated with java code?

As node.js still lacks important functionality which exists in Java, I would like to use Java instead of node.js, and create the client using a web language (html, js, css..).
Electron is cross platform and so does java so it seems fit to have a solution getting the best of both worlds.
Does someone know of a way to integrate electron with java or have a different solution to the problem?
I made something similar, Java back-end with Electron GUI.
You can do it in more ways, it depends on what you need.
You can create a jar file and then execute it like terminal:
https://nodejs.org/api/child_process.html
Or you can open a socket communication and talk on a Port. (A lot of documentation:
Java (web)socket - Node.js client.io)
In this second way, you can do everything you want, but you have to create your communication protocol.
Your path is not foolish, I am very satisfied of the communication and usage in my work with Java + Electron .
I've created a small PoC where Java process is integrated with Electron front-end: https://github.com/jreznot/electron-java-app There you will find a simple TODO List application built with Vaadin/Jetty and Electron.
Personally i made my back-end java communicate with the front-end by creating a file with te data then sending it to the main.js to be processed.
DBus and winDbus seems to be an option here.
It creates nice abstraction and separation between "frontend" and backend
https://sourceforge.net/projects/windbus/
I'm going to test it on my own soon

Does client-side java work on a server?

Can I write client side java in intelliJ, and then simply put it on a server for it to run on a server? Or will I need to write in a specialised version of Java and need to use a specialised IDE instead?
I'm trying to make an app and run the primary functions on a server then have the app send requests and fetch the data from the server. (It will esentially be a search engine of sorts and queries will be made to the server, which will then apply filters and use my algorithms to perform a search, before returning a result to the mobile device). But I'm not sure if I can begin writing this java on intellij, just as I would when making say, a simple calculator, or if I would need to write the java using a specialised server variation and server IDE.
Thank you.
The Java language is the same no matter what, so your logic can be ported easily. However on a server you may use a framework that's different from one you'd use on a client (for example you tagged this android- there wouldn't be Activities or Views on a server. You'd use another framework instead, possibly Spring.) Or you could go frameworkless, but then you'll have to write a lot of code that the frameworks do for you.
As for IDE- an IDE is an editor. You can write Java in notepad if you want. There's no difference, its just what features make your life easier. And yes, IntelliJ is a common choice.
If you would like make your own website, you should go with JavaEE or better with Spring.
If you would like to make simple server side application which will listen on specific port then respond something, go with Sockets
Netty is interesting NIO Socket library

How can my Android app communicate with a native daemon?

So, I have a custom Android application running as System (built as a system app in my ROM). And Ive written a native daemon that works fine too and runs as root. However, I was wondering how the two can communicate? I know I can have the native daemon create a network socket and have the App connect to it, but using a local socket for IPC seems even better, but I am struggling to find example code for it.
I figured I could create the socket like as described here but I have no idea how to communicate with it in Java.
Any help would be much appreciated.
Also, at first I wrote a native library and used JNI to communicate with it from Java, but quickly realized that it obviously runs in the context of the app, so it cant be run as root, which is a requirement I have, and something the native daemon can do fine. Is using sockets the best alternative here or would Binder work too?
Thanks a ton!
The solution here was to look at AOSP and see how installd communicates with the Installer java app. In init.rc you see how the named local socket is created and in installd.c you see how native code communicates with the socket. In Installer.java you see how its done from Java land.
Dont think Binder would be the right way to go for my particular use case.

Java GUI + Server Issue

So far, I've been searching far and wide on the internet for the best practice when it comes to writing a Java server with a GUI (for stopping and starting it). I know that I have to run the server in a separate thread as the GUI but I was also thinking that it my be a little less complicated if I made each piece, the server and the GUI, in its own Java program or process. If I go with the latter, how do I interact with the server from the GUI if they aren't the same application. Would I just kill the process from Java. I really need some help (or maybe a tutorial).
P.S. I'm going to write the client for other PC's and android phones in the house so I could create a simple messaging system in the network for easy copy and paste between devices so I was considering building the GUI and server in with the client so I could distribute that and it would be two way but I'm not sure if thats the right approach or not.
Thanks!
You sir, are looking for an Application Server, like JBoss. Interact with it using web pages as the GUI. Use HTTP as your messaging protocol (POST and GET). Use Eclipse for Java EE
and read some tutorial / guide. It might be some to learn now, but you'll benefit from it later.
For your requested functionality, create a web application with a servlet for receieving HTTP requests first.
I don't think there is a 'right' way to do this. If as you say, you want to have more than one client (an app running on PCs and an app running on android phones), then you are better off going for a client-server architecture, where your server and your client are two (or more in the case of the different GUIs you want to create) different programs.
The way they can communicate is also open for you to choose. You can go low level and connect through sockets, or you could use HTTP and create web clients.
If you give us a bit more context about what you want to create (server and client are way too generic words) then we could give more tailored questions.

intranet chat application using java

Any help would be great please..!
How to build an intranet chat application using java which includes transform of files like gtalk?
where to start the process?
what all the sw requirements?
The Eclipse Communication Framework includes several use cases based upon real-time shared editing over XMPP/Google Talk and Skype
And ECF is the base for a twitter client (as an example of what you can do with that framework)
you must have learned networking in java (java.net.*)
be sure of what king d of architecture you want to use
client/server
p2p
xmpp
If you need to deploy one, you can use Jabber with one of many Java Clients out there.
If you need to write your own server and/or client, you can start with this question and use an existing XMPP (IM protocol) libraries.
Why build one when good open source solutions based on open standards are available.
Take a look at running an Openfire XMPP (Jabber) server.
Theres a variety of clients available the best being:
Spark
Pidgin
I beleive that a flash client is also available.

Categories

Resources