您的位置:首页 > 理论基础 > 计算机网络

在RL-TCPnet下的UDP通信

2010-01-29 12:24 141 查看
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. 其他。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: