Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

App Engine Flexible Environment - Web Socket Example

This sample demonstrates how to use Websockets on Google App Engine Flexible Environment using Java. The sample uses the native Jetty WebSocket Server API to create a server-side socket and the native Jetty WebSocket Client API.

Sample application workflow

  1. The sample application creates a server socket using the endpoint /echo.
  2. The homepage (/) provides a form to submit a text message to the server socket. This creates a client-side socket and sends the message to the server.
  3. The server on receiving the message, echoes the message back to the client.
  4. The message received by the client is stored in an in-memory cache and is viewable on the homepage.

The sample also provides a Javascript client(/js_client.jsp) that you can use to test against the Websocket server.

Setup

  • Install and initialize GCloud SDK. This will
   gcloud init
  • If this is your first time creating an app engine application

      gcloud appengine create

Deploy

The sample application is packaged as a jar and runs on the Java 25 runtime.

mvn clean package appengine:deploy

You can then direct your browser to https://YOUR_PROJECT_ID.appspot.com/

To test the Javascript client, access https://YOUR_PROJECT_ID.appspot.com/js_client.jsp

Note: This application constructs a Web Socket URL using getWebSocketAddress in the SendServlet Class. The application assumes the latest version of the service.