|
Here is why the connect function of this program has not been successful?
I suspect that the parameter struct sockaddr_in sa is passed incorrectly, which brother can help me a little. It's pressed tightly.
BOOL IP100ComSendToNet (const unsigned char * IpAddr, const unsigned char * DataBuf)
{
struct sockaddr_in sa;
unsigned int ret;
SOCKET socketId;
int status;
Ranch
IP100ComIpAdrStringToData (IpAddr,&ret);
Ranch
sa.sin_family = AF_INET;
sa.sin_port = htons (9000);
sa.sin_addr.S_un.S_addr = htons (ret);
Ranch
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);
}
}
Ranch
close (socketId);
return OK;
} |
|