com.google.android.gms.games.multiplayer.realtime.RealTimeSocket |
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.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Closes this real-time socket connection with the participant.
| |||||||||||
Use this to read data from this socket.
| |||||||||||
Instance of
OutputStream to write data to. | |||||||||||
Returns the underlying file descriptor for direct read/write access.
| |||||||||||
Use this to check if the socket is closed.
|
Closes this real-time socket connection with the participant.
IOException | on error. |
---|
Use this to read data from this socket. Calling close() on the InputStream will close the socket.
InputStream
.IOException | on error. |
---|
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
.
OutputStream
.IOException | on error. |
---|
Returns the underlying file descriptor for direct read/write access. Calling close() on the returned ParcelFileDescriptor will close the socket.
ParcelFileDescriptor
or null if the underlying
socket is closed.IOException | in case of error. |
---|
Use this to check if the socket is closed.