Last change
on this file since 66 was 66, checked in by cheese, 11 years ago |
#1 add codec module (bin <-> hex-string)
|
File size:
910 bytes
|
Rev | Line | |
---|
[35] | 1 | /**
|
---|
| 2 | * @file socket_server.c
|
---|
| 3 | * @author myusgun <myusgun@gmail.com>
|
---|
| 4 | */
|
---|
| 5 | #include "cf_socket.h"
|
---|
| 6 | #include <stdio.h>
|
---|
| 7 |
|
---|
| 8 | int main (void) {
|
---|
| 9 | int srvsock = 0;
|
---|
| 10 | int clntsock = 0;
|
---|
| 11 | unsigned short port = 12345;
|
---|
[46] | 12 | int result = 0;
|
---|
[35] | 13 | char buf[1024] = {0x00,};
|
---|
| 14 |
|
---|
| 15 | if (CF_Socket_Initialize () < 0) {
|
---|
| 16 | // error
|
---|
| 17 | }
|
---|
| 18 | srvsock = CF_Socket_Server (port, 5);
|
---|
| 19 | if (srvsock < 0) {
|
---|
[46] | 20 | fprintf (stderr, "error : server (%d)\n", srvsock);
|
---|
[35] | 21 | }
|
---|
[46] | 22 |
|
---|
[53] | 23 | clntsock = CF_Socket_Accept (srvsock);
|
---|
[35] | 24 | if (clntsock < 0) {
|
---|
[46] | 25 | fprintf (stderr, "error : accept (%d)\n", clntsock);
|
---|
[35] | 26 | }
|
---|
[46] | 27 |
|
---|
| 28 | result = CF_Socket_Recv (clntsock, buf, sizeof (buf));
|
---|
| 29 | if (result < 0) {
|
---|
| 30 | fprintf (stderr, "error : recv (%d)\n", result);
|
---|
[35] | 31 | }
|
---|
[46] | 32 | fprintf (stderr, "server recv : %s(%d)\n", buf, result);
|
---|
| 33 |
|
---|
| 34 | result = CF_Socket_Send (clntsock, buf, result);
|
---|
| 35 | if (result < 0) {
|
---|
| 36 | fprintf (stderr, "error : send (%d)\n", result);
|
---|
[35] | 37 | }
|
---|
[46] | 38 |
|
---|
[35] | 39 | CF_Socket_Close (srvsock);
|
---|
| 40 | CF_Socket_Finalize ();
|
---|
| 41 |
|
---|
| 42 | return 0;
|
---|
| 43 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.