Last change
on this file since 48 was 48, checked in by cheese, 11 years ago |
#1 add socket option (reuseaddr and linger) and fix test code bug
|
File size:
844 bytes
|
Rev | Line | |
---|
[35] | 1 | /**
|
---|
| 2 | * @file socket_client.c
|
---|
| 3 | * @author myusgun <myusgun@gmail.com>
|
---|
| 4 | * @version 0.1
|
---|
| 5 | */
|
---|
| 6 | #include "cf_socket.h"
|
---|
| 7 | #include <stdio.h>
|
---|
[39] | 8 | #include <string.h>
|
---|
[35] | 9 |
|
---|
| 10 | int main (void) {
|
---|
| 11 | int sock = 0;
|
---|
[46] | 12 | int result = 0;
|
---|
[35] | 13 | char buf[] = "http://unsigned.kr";
|
---|
| 14 | unsigned short port = 12345;
|
---|
| 15 |
|
---|
| 16 | if (CF_Socket_Initialize () < 0) {
|
---|
| 17 | // error
|
---|
| 18 | }
|
---|
| 19 | sock = CF_Socket_Connect ("localhost", port);
|
---|
| 20 | if (sock < 0) {
|
---|
[46] | 21 | fprintf (stderr, "error : connect (%d)\n", sock);
|
---|
[35] | 22 | }
|
---|
[46] | 23 |
|
---|
| 24 | result = CF_Socket_Send (sock, buf, sizeof (buf));
|
---|
| 25 | if (result < 0) {
|
---|
| 26 | fprintf (stderr, "error : send (%d)\n", sock);
|
---|
[35] | 27 | }
|
---|
| 28 | memset (buf, 0x00, strlen (buf));
|
---|
[46] | 29 |
|
---|
| 30 | result = CF_Socket_Recv (sock, buf, sizeof (buf));
|
---|
| 31 | if (result < 0) {
|
---|
| 32 | fprintf (stderr, "error : recv (%d)\n", result);
|
---|
[35] | 33 | }
|
---|
[48] | 34 | fprintf (stderr, "client recv : %s(%d)\n", buf, result);
|
---|
[46] | 35 |
|
---|
[35] | 36 | CF_Socket_Close (sock);
|
---|
| 37 | CF_Socket_Finalize ();
|
---|
| 38 |
|
---|
| 39 | return 0;
|
---|
| 40 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.