Use Java Library in Javascript - javascript

I am planning a project where I will develop bots for Agar.io by using the NEAT algorithm, which is implemented in Java (this is called ANJI). I will use the open-source Agar.io server called Ogar, which is implemented in Javascript. The Javascript implementation should communicate with the Java library to evolve the bots while the game is running, but I have no previous experience of how to make Java and Javascript communicate. I have considered using Rhino, but it does not seem like it is possible to use in a browser. So, are there any way to let a Javascript implementation like Ogar use a Java library?

using the Rhino / Nashorm is not relevant in this case and as for performance focus its should be much hard to run nodeJS based application via Java JS engine.
the Agar.io server is a NodeJS server that expose a WebSocket API and the client solution need to communicate this way.
Using spring websocket client for example
have you seen Agar.io-bot ? its seems like the way they implement the BOT is javascript browser extension and communicate via the browser.

In common, Javascript and Java library communicate using Rest and Json, Java provide Rest API and Javascript send Json request to this API.
This is list of java library: for developing Java Rest API and working with JSON. I recommend using RESTEasy.

Related

HTML Javascript and Java runtime communication

My group has a project that is upposed to connect a web page to a databse. the webpage is written in html, css, and javascript, and the database is written in mysql. we know there are issues with accessing databases from javascript, so we built a driver class from java that is supposed to control communication between the two.
the problem is that we do not know how to connect javascript with java during runtime. the way it is built, the javascript simply needs to call a java function and get the results. is there any simple way to do this? perhaps a certain library? we have little to no knowledge of other similar tools (i.e. jsp, xml) and would like to stick to the languages listed above.
You can create a Java HTTP JSON server and then make a call to it from Javascript by using AJAX calls.
See here: Java simple HTTP JSON server
In order to provide easy access to java code(including static/dynamic web content) over HTTP interface you've to use one of the (servlet) containers - jetty, tomcat, spring-boot, etc.
In my opinion, since you've minimal experience developing/deploying java web applications jetty might be good option as it have good documentation to get started. Spring Boot is popular choice for Enterprise web development using Java - it might be more than you want to chew for the moment.
The Servlet(web) and JDBC(database) APIs what you will end up using on Java side.

Java: How do we call java methods from Javascript

For most of time I have worked on the server side using Java, Spring, Hibernate and databases. But now I have decided to learn front end programming using HTML5, CSS3 and Javascript.
I have a simple and elementary question here. How do we invoke java methods from java script ? For example on click of a button or to perform some validations on the server side.
I understand that we can perform ReST calls using Jersey. Are there any other ways to make a call to Java from JavaScript. Since I am a beginner here, I don't want to use Ajax, Servlets or JSP for now.
I have already built a simple application using SWT: SWT: Table Resizing Issue. I am thinking of using this opportunity to learn web programming.
I have already tried searching for answer on StackOverflow but couldn't find one. I hope that I am not duplicating any question.
Thanks.
If you are building a web application that run on the browser (because JavaScript can be also used to build desktop application: NodeJS, Electron…), so everything going from the browser to the backend server should be a http request, this is how the web work. Server Side framework is just doing the job of behalf of you by transforming backend code (Java, .NET, PHP …) to Browser language (html, css and JavaScript) and then performing server call using Http methods (Get, Post …).

Best way for implementing JavaScript lib in Java WebApplication

I am an Android developer and I am new to java web development, so please apologize if my thought is wrong. In our web app project we have to compare images (GIF/PNG/JPEG) and have to show the result.
We got a javascript lib (Resemble.js) which will compare the images and will give the result.
Please help on implementing this lib to my web app project. As its a js lib we can implement it only in front end right? If so is this a correct way? Because we have all other process in backend. Or else how to use a js lib in backend
Or let me know the best way in implementing the same. We are using React.js for front-end.
To execute javascript you need a javascript engine. A java virtual machine is not designed to run javascript so short answer is: You should use the Resemble.js into your front-end browser's engine (or into a back-end server that process javascript like Node.js).
Long answer: There are implementation of JavaScript written in Java that you could use (I don't konw if supports HTML). Take a look at: How can I run JavaScript code at server side Java code?

Socket.io/Node.js & SCTP?

I am developing an web application that will use web sockets to dynamically update the website for the user. The idea is to have changes in the back-end engine be dynamically transmitted. In order to do that, I want to use a Node.js server as a link between the web browser and back-end engine. Unfortunately, Node.js/JavaScript does not support SCTP sockets, which is what the back-end engine is using. Can you think of any way around this? It would be a shame if I couldn't use Socket.io and would have to deploy my own Javascript plugin & Java websocket server.
You can write the SCTP part in C or C++ and then write an addon to make it available in Node.js. I am currently trying that for one of my projects using SCTP.
Of cource, this is not super elegant, not very portable and it is some extra work, but if you really want to use Node.js, this is one of the possible ways...

rapidly create webpage front end

Exposition:
I'm familiar with C/C++/Scheme & OpenGL. I have this client/server program written in Clojure that serves as a todo-list/wiki/forum. The server is written in Clojure. The client is written in Clojure and uses SWT.
Question:
I want to rapidly create a web client version of this. What is the best way to do this? (I Don't use anything complicated, like OpenGL rendering in SWT; just standard widget stuff) I just want something accessible via Safari/Firefox -- and no, I don't want to run it as a Java Applet.
Thanks!
Take a look at Ruby on Rails, allows you to create very basic CRUD applications quickly. Personally I am looking more a Grails a very similiar framework but for a Java platform
Ruby On Rails - http://rubyonrails.org/
Failing either of those PHP is a good alternative and very quick to get started with
Adobe Flex/Actionscript is a pretty good approach for applications that require rich user interaction.
Google Web Kit allows writing of Java code (since server is in Clojure) to create AJAX api.

Categories

Resources