前言
- 使用两个线程作为客户端中的收和发
- 使用线程挂起和线程恢复的api来实现
- 接收线程必须要保证在处理连接状态才能进行接收。
Demo
#include <string.h>
#include "lwip/api.h"
#include "FreeRTOS.h"
#include "task.h"
#define TCP_CLIENT_RX_BUFSIZE 256
static void tcp_client_send(void *);
static void tcp_client_rec(void *);
static TaskHandle_t client_send_handle;
static TaskHandle_t client_rec_handle;
static ip_addr_t server_ipaddr, loca_ipaddr;
static uint16_t server_port = 8080;
static struct netconn *tcp_conn;
static uint8_t tcp_client_recvbuf[TCP_CLIENT_RX_BUFSIZE] = {
0};
void create_netconn_tcp_client_thread() {
xTaskCreate((TaskFunction_t) tcp_client_send,
(const char *) "tcp_client_send"