Socket.read

From Spheriki

Jump to: navigation, search

Reads data from a socket, and returns it in the form of a ByteArray.


Contents

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.


Examples

See example for OpenAddress(), the third step (// 3. If connected, send and receive data.).


Notes

  • Data sent from another computer to a game on the current computer is obtained using this function.
  • The size parameter 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.


See also

Personal tools