int main(void) { tcp_server_data_t * server; tcp_client_data_t * client; int i; char message[MAX_BUFFER_LEN]; i= 0; server = tcp_server_data_new(); strcpy(server->port,"8675"); client = tcp_client_data_new(); strcpy(client->dest_ip_address,"localhost"); strcpy(client->port,"8675"); tcp_server_start(server); tcp_client_start(client); printf("testing server and client with 5 messages\n"); while(i<5) { sleep(1); sprintf(message, "ack from client %d\n",i); thread_copy_to_buffer(client->send_buffer, message); sprintf(message, "boo form server %d\n",i); thread_copy_to_buffer(server->send_buffer, message); i++; } printf("shutting down! this isnt pretty yet, but its ok :) \n"); tcp_client_stop(client); tcp_client_data_free(client); tcp_server_stop(server); tcp_server_data_free(server); printf("goodbye!\n"); return 0; }
int tun_start(struct tundev *tun) { uv_loop_t *loop = uv_default_loop(); struct tundev_context *ctx = tun->contexts; tcp_client_start(ctx, loop); uv_poll_init(loop, &ctx->watcher, ctx->tunfd); uv_poll_start(&ctx->watcher, UV_READABLE, poll_cb); #ifndef ANDROID signal_install(loop, signal_cb, tun); #endif uv_run(loop, UV_RUN_DEFAULT); loop_close(loop); return 0; }