1. 初始化TCPnet。
void init_TcpNet (void);
2. 分配自由的UDP Socket。
U8 udp_get_socket (
U8 tos, /* Type Of Service. */
U8 opt, /* Option to calculate or verify the checksum. */
U16 (*listener)(/* Function to call when TCPnet receives a data packet. */
U8 socket, /* Socket handle of the local machine. */
U8* remip, /* Pointer to IP address of remote machine. */
U16 port, /* Port number of remote machine. */
U8* buf, /* Pointer to buffer containing the received data. */
U16 len ));
Listener是udp的事件侦听函数,TCPnet随时在收到一个UDP包时调用它。
3. 打开它。
BOOL udp_open (
U8 socket, /* Socket handle to use for communication. */
U16 locport); /* Local port to use for communication. */
4. 运行TCPnet的主线程。
void main_TcpNet (void);
5. 监听或发送。
BOOL udp_send (
U8 socket, /* UDP socket to send the data packet from. */
U8* remip, /* Pointer to the IP address of the remote machine. */
U16 remport, /* Port number of remote machine to send the data to. */
U8* buf, /* Pointer to buffer containing the data to send. */
U16 dlen ); /* Number of bytes of data to send. */
注意:在发送数据时,必须用udp_get_buf为udp_send()函数分配内存。
U8* udp_get_buf ( U16 size); /* Number of bytes to be sent. */
6. 其他。