Overview of Sockets API for Java

This is a Beta release of the Sockets API. This API is not covered by any SLA or deprecation policy and may be subject to backward-incompatible changes.

Important: Applications in the Java 8 runtime default to using native Java sockets with no restrictions: Google recommends that you keep this default. This includes the ability to use the NIO classes and methods, unlike Java 7 runtime apps, which are subject to the sockets limitations described on this page.


Sockets are only available for paid apps, and traffic from sockets is billed as outgoing bandwidth. Sockets are also limited by daily and per minute (burst) quotas.

The Java 7 runtime supports a limited outbound Java socket using a modified version of java.net.Socket and java.net.DatagramSocket.

The Java 7 runtime does not support java.nio.SocketChannel java.nio classes, or the ability to call get or set options against sockets. Using these features will raise Not Implemented exceptions. These restrictions\ are lifted by default when using the Java 8 runtime.

The supported options for Java 7 runtime apps are:

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

Limitations and restrictions (Java 7 runtime only)

Although App Engine supports sockets, there are certain limitations and behaviors you need to be aware of when using sockets in the Java 7 runtime:

  • Sockets are available only for paid apps.
  • You cannot create a listen socket; you can only create outbound sockets.
  • FTP is not supported.
  • java.net.URL is still configured to use the URL Fetch API in the Java 7 runtime. To get around this limitation, you can run your app in the Java 8 runtime, where java.net.URL and java.net.HttpURLConnection use Java native sockets by default.
  • InetAddress.isReachable is a no-op.
  • 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 (Java 7 runtime only)

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

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

App Engine standard environment for Java