|
下面是这个程序的connect函数为什么一直都不成功呢?
我怀疑是struct sockaddr_in sa这个参数传递错误,麻烦哪位大哥帮一下忙。上面压得很紧阿。
BOOL IP100ComSendToNet(const unsigned char *IpAddr,const unsigned char *DataBuf)
{
struct sockaddr_in sa;
unsigned int ret;
SOCKET socketId;
int status;
IP100ComIpAdrStringToData(IpAddr,&ret);
sa.sin_family=AF_INET;
sa.sin_port=htons(9000);
sa.sin_addr.S_un.S_addr = htons(ret);
socketId=socket(AF_INET, SOCK_DGRAM,0);
if(socketId == ERROR)
printf("socket fail:%d\n", ERROR);
if(ret != ERROR)
{
if(connect(socketId,(struct sockaddr_in *) &sa, sizeof(sa)) == ERROR)
//if(connect(socketId,(const struct sockaddr FAR*) &sa, sizeof(sa)) == ERROR)
printf("send fail:%d\n", ERROR);
else
{
printf("send success:%d\n", OK);
status = send(socketId, DataBuf, strlen(DataBuf), 0);//MSG_DONTWAIT);
}
}
close(socketId);
return OK;
}
|
|