Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Sockets Java API Overview

This is a Preview release of the Socket API. As a result, the API is subject to change and the service itself is currently not covered by any SLA or deprecation policy. These characteristics will be evaluated as the API and service moves towards General Availability, but developers should take this into consideration when using the Preview release of Socket API.

App Engine supports regular outbound Java sockets such as java.net.Socket and java.net.DatagramSocket . There is currently no support for sockets via java.nio.SocketChannel or other java.nio classes. The Sockets API allows client code to call get/set options against sockets. (Previously, calls raised Not Implemented exceptions.)

The currently supported options are:

  • SO_KEEPALIVE
  • SO_DEBUG
  • TCP_NODELAY
  • SO_LINGER
  • SO_OOBINLINE
  • SO_SNDBUF
  • SO_RCVBUF
  • SO_REUSEADDR

Limitations and restrictions

App Engine supports sockets without requiring you to import any special App Engine libraries or add any special App Engine code. However, there are certain limitations and behaviors you need to be aware of when using sockets:

  • Sockets are available only for paid apps.
  • You cannot create a listen socket; you can only create outbound sockets.
  • java.net.URL is still configured to use the URL Fetch API ; there is currently no way around this.
  • Most classes in javax.net.ssl are supported.
  • You can only use TCP or UDP; arbitrary protocols are not allowed.
  • You cannot bind to specific IP addresses or ports.
  • Port 25 (SMTP) is blocked; you can still use authenticated SMTP on the submission port 587.
  • Private, broadcast, multicast, and Google IP ranges (except those whitelisted below), are blocked:
    • Google Public DNS: 8.8.8.8 , 8.8.4.4 , 2001:4860:4860::8888 , 2001:4860:4860::8844 port 53
    • Gmail SMTPS: smtp.gmail.com port 465 and 587
    • Gmail POP3S: pop.gmail.com port 995
    • Gmail IMAPS: imap.gmail.com port 993
  • Socket descriptors are associated with the App Engine app that created them and are non-transferable (cannot be used by other apps).
  • Sockets may be reclaimed after 2 minutes of inactivity; any socket operation keeps the socket alive for a further 2 minutes.
  • You cannot Select between multiple available sockets because that requires java.nio.SocketChannel which is not currently supported.)

Using sockets with the development server

You can run and test code using sockets on the development server, without using any special command line parameters.

App Engine sample using sockets

For a sample using sockets, see the socket demo app in the Google Cloud Platform GitHub.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.