Jonathan Laliberte
Jonathan Laliberte

Reputation: 2725

Websocket or native sockets for google appengine with java 8?

I currently use HTTP Long Polling for the user messaging & notification system of my java 8 based webapp (standard environment) on Google's AppEngine. I'd like to implement this with the Socket API.

On Google's documentation about the Java Sockets API it mentions:

Important: Applications in the Java 8 runtime can use native Java sockets with no restrictions, including the use of NIO classes and their methods.

So i'm a little confused as to what i should be using exactly, websockets or native java sockets? There's a difference right? Apparently the Java 8 runtime has changed the socket api considerably, is this why it's possible to use native java sockets instead of websockets?

Upvotes: 1

Views: 808

Answers (2)

Chanseok Oh
Chanseok Oh

Reputation: 4306

The Java 7 runtime, which is now deprecated, is a special sandboxed environment. As such, it has many restrictions in terms of what you could do on its JVM, for example, regarding threading, available classes from the standard Java library, sockets, security manager, etc.

The Java 8 runtime has a vastly different infrastructure, and most of the restrictions have been lifted. It supports the standard public Java library (which of course includes the native Java sockets and the NIO), not just the whitelisted subset of them as in the Java 7 runtime. The quote from the doc you linked is just advertising the superiority of the Java 8 runtime over the Java 7 runtime.

I'd say it is up to you to decide whether you'll use the native Java socket. Using the standard Java library won't be a bad thing, at least.

EDIT: these additional docs might be of your interest too:

Upvotes: 3

Lautert
Lautert

Reputation: 505

This specific google documentation is talking about creating a java client to a websocket server outside your application - that's why it talks about the java 8 nio. Also the examples provided in that page (https://github.com/googlearchive/appengine-sockets-python-java-go/tree/master/java_socket_demo ) points out how to create a websocket client to query a dns server.

Now if you want to provide a websocket from your java application I could not find any documentation on google's documentation.

Upvotes: 1

Related Questions