-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
40 lines (34 loc) · 1.13 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include "network.h"
int8_t config_request_get(const struct string_st *data, struct string_st *response) {
if (response == NULL) return 1;
string_clear(response);
if (string_is_null(data)) return 0;
printf("data get : %s\n", data->data);
string_set_str(response, "321", 3);
return 0;
}
int8_t config_request_send(const struct string_st *data) {
if (string_is_null(data)) return 0;
printf("data send : %s\n", data->data);
return 1;
}
int main() {
struct network_conf config = (struct network_conf) {AF_INET, SOCK_STREAM, 0, INADDR_ANY, 1240, 20};
struct network_p2p network;
struct string_st str;
struct string_st res;
network_p2p_data_init(&network, config, &config_request_get, &config_request_send);
string_data_init(&str);
string_data_init(&res);
// network_p2p_start(&network);
network_server_connect(&network.server);
string_set_str(&str, "123", 3);
while(1) {
network_p2p_get(&network, &str, &res);
printf("res : %s\n", res.data);
}
string_data_free(&res);
string_data_free(&str);
network_p2p_data_free(&network);
}