<< Previous | Index | Next >>

sock_recv


int sock_recv( sock_type *s, char *buffer, int len );

Description

After a UDP socket is initialized with udp_open() and sock_recv_init(), sock_recv() scans the buffers for any datagram received by that socket.

This function is not available starting with Dynamic C 7.05 (see Section 3.5).

Parameters

s

Pointer to a UDP socket.

buffer

Buffer to put datagram.

maxlength

Length of buffer.

Return value

>0: Length of datagram.
 0: No datagram found.
-1: Receive buffer not initialized with sock_recv_init().

Library

DCRTCP.LIB

See also

sock_recv_from, sock_recv_init

Example using sock_recv()


// Old way of setting network addresses are commented out
//#define MY_IP_ADDRESS "10.10.6.100"
//#define MY_NETMASK "255.255.255.0"

// New way of setting network addresses. 
#define TCPCONFIG 1

#memmap xmem

#use "dcrtcp.lib"
#define SAMPLE 401

udp_Socket data;
char bigbuf[ 8192 ];

main() {
word templen;
char spare[ 1500 ];

   sock_init();
if ( !udp_open( &data, SAMPLE, 0xffffffff, SAMPLE, NULL)
{
puts("Could not open broadcast socket");
exit( 3 );
}

   /* set large buffer mode */
if ( sock_recv_init( &data, bigbuf, sizeof( bigbuf ))) {
puts("Could not enable large buffers");
exit( 3 );
}

   sock_mode( &data, UDP_MODE_NOCHK );    // turn off checksums

   while (1) {
tcp_tick( NULL );

      if (templen = sock_recv(&data, spare, sizeof(spare )))
{
/*
something received */
printf("Got %u byte packet\n", templen );
}
}
}


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