socket_read
lib callCapy
function socket_read(handle : u64, max_length : s32 = 131072, timeout : s32 = 1) string
Description
socket_read waits for data and performs one read. max_length is a byte count, not a message length. A result can contain part of one message or data from several messages. Keep incomplete data until your protocol has a complete message.
timeout is in seconds. The default is one second. Zero uses the remaining request time budget. The request deadline always applies.
Return Values
A string containing up to max_length bytes from one socket read.
Errors
A timeout, a closed peer, an invalid handle, a read failure, or a zero max_length returns "". This call does not distinguish these conditions. Do not retry indefinitely on an empty result.
Example
Capy
var handle := socket_connect("127.0.0.1", 11211)
if handle != 0
{
socket_write(handle, "version\r\n")
print(socket_read(handle, 64, 1))
socket_close(handle)
}
Output
VERSION 1.6.40