public interface

RealTimeSocket

com.google.android.gms.games.multiplayer.realtime.RealTimeSocket

Class Overview

Provides a Socket-like interface for a real-time data connection to a participant in a real-time room. Use getRealTimeSocketForParticipant(String, String) to get an instance.

Use getParcelFileDescriptor() to get a file descriptor for read/write, or use getInputStream() / getOutputStream() to get access to an instance of InputStream or OutputStream respectively.

Calling close() on any of (i) the returned ParcelFileDescriptor or, (ii) the InputStream or OutputStream instances will close the socket.

The Socket-like interface provided is currently modeled on connection-based byte streams, rather than preserving packet semantics. That is, multiple writes may be coalesced or individual writes divided. Clients should avoid calling write(byte[]) with more than MAX_UNRELIABLE_MESSAGE_LEN bytes at a time.

Summary

Public Methods
abstract void close()
Closes this real-time socket connection with the participant.
abstract InputStream getInputStream()
Use this to read data from this socket.
abstract OutputStream getOutputStream()
Instance of OutputStream to write data to.
abstract ParcelFileDescriptor getParcelFileDescriptor()
Returns the underlying file descriptor for direct read/write access.
abstract boolean isClosed()
Use this to check if the socket is closed.

Public Methods

public abstract void close ()

Closes this real-time socket connection with the participant.

Throws
IOException on error.

public abstract InputStream getInputStream ()

Use this to read data from this socket. Calling close() on the InputStream will close the socket.

Returns
Throws
IOException on error.

public abstract OutputStream getOutputStream ()

Instance of OutputStream to write data to. Calling close() on the OutputStream will close the socket.

Note: The maximum (unfragmented) packet size supported through this API is MAX_UNRELIABLE_MESSAGE_LEN bytes (excluding internal protocol headers). Thus, the byte[] data passed to write(byte[]) should honor this limit or the packet will be dropped and an error message will be sent to the log.

Do not call flush() on the OutputStream instance that you obtained from this routine. To send each message as a single datagram, implement your own message parsing logic to distinguish message boundaries. This allows partial messages and a non-integral number of messages to be delivered using RealTimeSocket.

Returns
Throws
IOException on error.

public abstract ParcelFileDescriptor getParcelFileDescriptor ()

Returns the underlying file descriptor for direct read/write access. Calling close() on the returned ParcelFileDescriptor will close the socket.

Returns
Throws
IOException in case of error.

public abstract boolean isClosed ()

Use this to check if the socket is closed.

Returns
  • True if the socket is closed.