目录
2.接下来我们需要将网络连接结构体赋值,在这里我们将它设置为udp通信有两个方法
udp通信 8266作为服务器等待客户端向他主动发起通信
1.定义espconn型结构体(网络连接结构体)
struct espconn ST_NetCon; // 注:必须定义为全局变量,内核将会使用此变量(内存)
struct espconn {
/** type of the espconn (TCP, UDP) */
enum espconn_type type; //网络连接的类型 tcp/udp
/** current state of the espconn */
enum espconn_state state; //网络连接的状态
union {
esp_tcp *tcp;
esp_udp *udp;
} proto;
/** A callback function that is informed about events for this espconn */
espconn_recv_callback recv_callback; //回调函数
espconn_sent_callback sent_callback; //回调函数
uint8 link_cnt; //连接数量
void *reverse; //void* 指针
};
typedef struct _esp_udp {
int remote_port; //远端主机端口号
int local_port; //8266端口号
uint8 local_ip[4]; //8266ip地址
uint8 remote_ip[4]; //远端主机ip地址
} esp_udp;
2.接下来我们需要将网络连接结构体赋值,在这里我们将它设置为udp通信有两个方法
法一:创建一个udp通信结构体,并且将udp通信结构体的指针赋值给网络连接结构体中存放upd结构体指针的成员
esp_udp ST_UDP; // UDP通信结构体 ST_NetCon.proto.udp = &ST_UDP;
法二: ST_NetCon.proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp));