<< Previous | Index | Next >>

sock_gets


int sock_gets( tcp_Socket * s, char * dp, int len );

Description

Read a string from a socket and replace the CR or LF with a '\0'. If the string is longer than len, the string is null terminated and any remaining characters will be returned on the next sock_gets() call. This function is only valid for TCP sockets.

To use sock_gets(), you must first set ASCII mode using the function sock_mode()or the macro tcp_set_ascii().

Parameters

s

Pointer to a socket

dp

Buffer to put the string.

len

Max length of buffer.

Return value

 0: The buffer is empty; or no '\r' or '\n' was read, plus the buffer has room and the connection can get more data.
>0: The length of the string.
-1: Function was called with a UDP socket ( valid for Dynamic C 7.05 and later).

Library

TCP.LIB (Prior to DC 7.05, this was DCRTCP.LIB)

See also

sock_puts, sock_putc, sock_getc, sock_read, sock_write

Example


sock_mode( s, TCP_MODE_ASCII );
do {
if (sock_bytesready( s ) > 0) {
sock_gets( s, buffer, sizeof(buffer)-1 );
puts( buffer );
}
} while (tcp_tick( s );


TCP/IP Manual
Vol 1
<<Previous | Index | Next>> rabbit.com