Socket.read
From Spheriki
Reads data from a socket, and returns it in the form of a ByteArray.
Contents |
[edit]
Usage
ByteArray Socket.read(size);
- Socket Sphere Socket object. The socket from which to read the data.
- size Number, integer, positive. The number of bytes to read from the socket. This value is commonly obtained by calling Socket.getPendingReadSize().
- ByteArray is returned, holding the bytes of data obtained from the socket.
[edit]
Examples
See example for OpenAddress(), the third step (// 3. If connected, send and receive data.).
[edit]
Notes
- Data sent from another computer to a game on the current computer is obtained using this function.
- The
sizeparameter can be any value you want, but it is most commonly obtained by calling Socket.getPendingReadSize().
- If the ByteArray object received represented a string (i.e. the server sent a string converted into a byte array), the string can be obtained by passing the result of this function through CreateStringFromByteArray().
- To send data over the socket rather than receive it, use the Socket.write() function.
[edit]
See also
- Sphere Socket object
- Sphere ByteArray object
- CreateStringFromByteArray()

