Changeset 34 in libcf for trunk/include/cf_socket.h


Ignore:
Timestamp:
02/05/13 11:26:59 (11 years ago)
Author:
cheese
Message:

#1 add example code for doxygen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/cf_socket.h

    r26 r34  
    33 * @author  myusgun <myusgun@gmail.com>
    44 * @version 0.1
    5 
     5 *
    66 * @remark TCP 소켓만 지원됨
     7 *
     8 * @section 샘플코드(서버)
     9 * @code
     10
     11#include "cf_socket.h"
     12
     13int main (void) {
     14    int srvsock = 0;
     15    int clntsock = 0;
     16    short port = 12345;
     17    int recvd = 0;
     18    char buf[1024] = {0x00,};
     19
     20    if (CF_Socket_Initialize () < 0) {
     21        // error
     22    }
     23    srvsock = CF_Socket_Server (port, 5);
     24    if (srvsock < 0) {
     25        // error
     26    }
     27    clntsock = CF_Socket_Accept (srvsock, NULL);
     28    if (clntsock < 0) {
     29        // error
     30    }
     31    if ((recvd = CF_Socket_Recv (clntsock, buf, sizeof (buf))) < 0) {
     32        // error
     33    }
     34    if (CF_Socket_Send (clntsock, buf, recvd) < 0) {
     35        // error
     36    }
     37    CF_Socket_Close (srvsock);
     38    CF_Socket_Finalize ();
     39
     40    return 0;
     41}
     42
     43 * @endcode
     44 *
     45 * @section 샘플코드(클라이언트)
     46 * @code
     47
     48#include "cf_socket.h"
     49
     50int main (void) {
     51    int sock = 0;
     52    int recvd = 0;
     53    char buf[1024] = {0x00,};
     54    short port = 12345;
     55
     56    if (CF_Socket_Initialize () < 0) {
     57        // error
     58    }
     59    sock = CF_Socket_Connect ("localhost", port);
     60    if (sock < 0) {
     61        // error
     62    }
     63    if (CF_Socket_Send (sock, buf, sizeof (buf)) < 0) {
     64        // error
     65    }
     66    if ((recvd = CF_Socket_Recv (sock, buf, sizeof (buf))) < 0) {
     67        // error
     68    }
     69    CF_Socket_Close (sock);
     70    CF_Socket_Finalize ();
     71
     72    return 0;
     73}
     74
     75 * @endcode
    776 */
    877#ifndef __CF_SOCKET_H__
Note: See TracChangeset for help on using the changeset viewer.