This is very new thing for me.
I am just wondering If we could send the ProtoBuf serialized data from java application to Web application (javascript) and de-serialize there. I am using TCP/IP connection in websocket to connect java application to javascript.
I have been looking at
https://github.com/dcodeIO/ProtoBuf.js/
but they are using node.js ,which is not in my case.
Thank you
ProtoBuf.js also runs in the browser. Basically, all you have to do is to connect your client to your Java server using a (binary) WebSocket and to send ProtoBuf packets back and forth.
Here is an example that decodes a message on the client side.
Related
I have implemented a websocket server using nanohttpd in java. I can access the websocket server from js in a web page. It works great.
However, now I'd like to create a java based client that will connect to the same server.
Does nanohttpd have a set of java classes to connect to the websocket server? In other words, the server is running in java but now I want a separate java client program to connect to it.
If so, what is the minimum java code to connect to the server?
If not, how would you suggest I connect to the websocket server in java?
There are plenty of third party Java Web Socket client implementations you can use. This is one of them.
I'm trying to build a Java web app that will let me browse a remote file system behind my NAT router. The client can talk outbound HTTP only.
I've got my Java client on the remote machine talking to my Tomcat server, which is then serving the data back up as web pages. Something like this:
File Server (java client) -> Web Server <- Browser
What I can't figure out is how to have the Tomcat server talk back to the remote Java client.
What I want to happen is:
User clicks on a folder in their browser.
Browser ajaxes to the server.
The Tomcat server contacts the remote java client.
The remote java client responds with the directory listing.
The Tomcat server sends back the new data formatted as HTML to the user.
I've looked at Comet and Tomcat 7's asynchronous stuff but I'm struggling!
If you need full-duplex communication over HTTP, than I strongly recommend using Atmosphere and Web Sockets. It simplifies server push a lot, and it's container agnostic (the framework).
You can use Async Http Client library for your remote java client in that case.
If you want to implement a PUSH behavior, then Commet is the way to go.
If there are few clients, perhaps you could solve your requirements by allowing the client to continuosly PULL changes from the server each few seconds.
Having a NodeJS + SocketIO server in javascript. Are there options to have a Java application to connect to that NodeJS/SocketIO server so that it can publish and subscribe messages?
I made something similar recently for teaching (node.js server, java client in publish/subscribe).
Actually, you should consider Faye : http://faye.jcoglan.com/
You can attach a websocket and/or bayeux server in a node.js instance using faye.
You can then connect any client that implement one or both of these protocol.
I successfully used it in the past for a lab with students in which a server is node.js publishing information, and a java client subscribe to faye using the cometd library (http://cometd.org/).
Source code of :
this server with faye but also traditional http server is located at : https://github.com/cgravier/WI-UCLab/blob/master/context-server-nodejs/simulateArduino.js
the java client using Cometd : https://github.com/cgravier/WI-UCLab/tree/master/context-client-java (sorry it is a library hell, it is designed for student that I was explicitly told were not familiar with maven (or equivalent), and it is 3h lab... anyway.)
Although the document is in French, I guess the figure at page 4 in https://github.com/cgravier/WI-UCLab/blob/master/lab%20document/context-awareness.pdf is self explanable.
HTH
fafhrd
I have used this one android-websockets which includes both SocketIO and Pure Websockets communication, but did not find it so stable, it had issues connecting to the server but this one socket.io-java-client seems like alright but have not used it.
I am trying to implement comet grizzly on my glassfish server v3.
I am trying to connect web server from desktop application using http url object.
I am creating ObjectInputStreamer and ObjectOutputStreamer at both client and web server.
In webserver servlet I am creating ObjectOutputStream to write response back to client.
And this output streamer I am attaching to handling of comet so that I could push data to client without request on same response channel afterwards.
and on client I am not closing the InputStreamer so that I can read the response pushed by webserver using comet.
But on writing data on output stream from webserver it is not giving any exception but still I am not able to read at client end which gives EOFException on reading from opened Input Stream.
Thanks,
Ali
Comet is a technique used to notify a client of changes on the server over an http internet connection. A good place to start learning comet are the examples here. Using the java.io.ObjectInput/OutputStream is for reading in files, passing serialized java objects, etc. They use the Object Serialization Stream Protocol, which won't work with comet.
I'm starting a new project where I need to send data from an Arduino to a Java Server. I would like to use the Arduino Wifi shield. Afterwards the java server will send the received data to a web service trough a 3G Router.
Is this setup possible? Does there exist an API to set up a socket connection between an Arduino and a Java Server?
If not which possibilities do i have? Thank in advanced
There is certainly a number of ways you can do this. You can use the Arduino Ethernet library to make connections to your Java server. Here's a nice little program called ClientConnect which uses the ethernet device to make a connection to a server. This little program sends a web request to the server with the following lines:
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
On the server side it would be easiest to use some sort of simple servlet and utilize a Java web framework such as Tomcat.
Your Arduino transactions would then just look like simple web transactions:
GET /your-path-to-your-servley?field1=value1&field2=value2 HTTP/1.0
[[ empty line here ]]
This will send a set of field/value pairs to your Java webserver which will call your servlet. In the example at the top, "q" is the field name and "arduino" is the value.
Hope this helps.
Similar to the answer by #gray which is a "push" solution, is to have the java server query the Arduino at some interval ("pull" model). To do this, just see the Web hosting example in Arduino's ethernet samnple library. You can modify it, to have the arduino return the value of its sensors as part of its http response.