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);
Содержание Optimus R
Страница 1: ...Printed on 20 March 2006 C Programming Guide Version 3 04 02 Optimus S Optimus R...
Страница 6: ......
Страница 8: ...2 C Programming Guide For Optimus S R...
Страница 12: ...6 C Programming Guide For Optimus S R The flow is illustrated as shown below...
Страница 23: ...Chapter 2 Development Environment 17 Different types signed unsigned Different types same size...
Страница 24: ...18 C Programming Guide For Optimus S R...
Страница 220: ...214 C Programming Guide For Optimus S R See Also FlashSize free_memory...
Страница 232: ...226 C Programming Guide For Optimus S R 4 11 Implementation defined Limits limits h float h Refer to limit h and float h...
Страница 238: ...232 C Programming Guide For Optimus S R...