contents   index   previous   next



Socket read()

syntax:

socket.read(destination, description)

where:

destination - A destination variable which will be converted to the appropriate type based on description.

 

description - A variable description, either one of the special Blob variables UWORD8, SWORD8, UWORD16, SWORD16, UWORD24, SWORD24, UWORD32, SWORD32, FLOAT32, FLOAT64, FLOAT80, a blobDescriptor object describing a structure, or a positive value indicating the length of a buffer to read.

 

return:

number - elements read.

 

description:

This method is almost identical to Clib.fread(), except that it reads from the current socket rather than a supplied file. The description variable acts in the same way as Clib.fread(). If it is a positive value, then destination is treated as a buffer and filled with raw data. Otherwise, one of the blob types or blob descriptors can be used to read data values. For buffers, the length of the buffer read is returned. For all other values, 1 is returned if the item is read successfully, -1 or 0 otherwise. Use Socket error() to determine the nature of the error. Typically, -1 means the socket is non-blocking and no data is available to read. 0 usually indicates that the program at the other end of the socket closed it.

 

see:

#link <sesock>, Clib.fread(), Socket write(), Socket error()

 

example:

function readInfo( socket )

{

   var description = new blobDescriptor();

   description.name = 12;

   description.age = UWORD8;

   description.extension = UWORD16;

   var info;

 

   if( !socket.read( info, description ) )

      return null;

   else

      return info;

}

 

/* The above function will read the special

 * info data structure from

 * the socket, returning null

 * if there is some sort of error.

 */

 


Socket ready()