144
"C" Programming Guide For Optimus S/R
accept
Purpose
To accept a connection on a socket.
Syntax
int accept (SOCKET s, struct sockaddr *name, int *namelen);
s
Descriptor identifying a socket in a listening state
name
Pointer to a sockaddr structure receiving the remote IP address
and port number
namelen
Pointer to an integer containing the length of
name
Example
SOCKET listen_socket, remote_socket;
struct sockaddr_in local_name, remote_name;
int size_of_name;
listen_socket = socket (PF_INET, SOCK_STREAM, TCP);
if (listen_socket < 0) {
printf ("SOCKET allocation failed");
.....................
}
memset (&local_name, 0, sizeof (local_name));
local_name.sin_family = AF_INET;
local_name.sin_port = htons (3000);
if (bind (listen_socket, (struct sockaddr*) &local_name, sizeof (local_name)) <
0) {
printf ("Error in Binding on socket: %d", listen_socket);
.....................
}
If (listen (listen_socket, 1)) {
printf ("Error in Listening on socket: %d", listen_socket);
.....................
}
size_of_name = sizeof (remote_name);
remote_socket =
accept (listen_socket, (struct sockaddr*)&remote_name, &size_of_name);
if (remote_socket < 0) {
printf ("Error in accept on socket: %d", listen_socket);
.....................
}
Send (remote_socket, "Hello", strlen ("Hello"), 0);
Summary of Contents for Optimus R
Page 1: ...Printed on 20 March 2006 C Programming Guide Version 3 04 02 Optimus S Optimus R...
Page 6: ......
Page 8: ...2 C Programming Guide For Optimus S R...
Page 12: ...6 C Programming Guide For Optimus S R The flow is illustrated as shown below...
Page 23: ...Chapter 2 Development Environment 17 Different types signed unsigned Different types same size...
Page 24: ...18 C Programming Guide For Optimus S R...
Page 220: ...214 C Programming Guide For Optimus S R See Also FlashSize free_memory...