首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

socket编程中sendto函数可以发结构体数据吗解决思路

2012-03-13 
socket编程中sendto函数可以发结构体数据吗msdn中sendto函数的定义intsendto(SOCKETs,constcharFAR*buf,in

socket编程中sendto函数可以发结构体数据吗
msdn中sendto函数的定义
int   sendto(
    SOCKET   s,
    const   char   FAR*   buf,  
    int   len,
    int   flags,
    const   struct   sockaddr   FAR*   to,
    int   tolen
);
Parameters
s  
[in]   Descriptor   identifying   a   possibly   connected   socket.  
buf  
[in]   Buffer   containing   the   data   to   be   transmitted.  
len  
[in]   Length   of   the   data   in   the   buf   parameter.  
flags  
[in]   Indicator   specifying   the   way   in   which   the   call   is   made.  
to  
[in]   Optional   pointer   to   the   address   of   the   target   socket.  
tolen  
[in]   Size   of   the   address   in   the   to   parameter.  
其中第二个参数是指向char型的指针,请问传递指向结构体的指针可以吗?
我的目的是想把结构体中的信息通过udp包从客户端发送给服务器端,服务器端可以读取结构体中包含的信息

[解决办法]
强制转换为char * 传送,服务器端使用结构的指针接收(也是在参数中强转为char *)

热点排行
Bad Request.