本文共 1154 字,大约阅读时间需要 3 分钟。
#pragma comment( lib, "ws2_32.lib" )
struct sockaddr_in ServerAddr;
char buf[ MAXDATASIZE ] = { "y" };
if( WSAStartup( MAKEWORD( 1, 1 ), &WSAData ) )
printf( "initializationing error!\n" );
if( ( iClientSock = socket( AF_INET, SOCK_DGRAM, 0 ) ) == -1 )
ServerAddr.sin_family = AF_INET;
ServerAddr.sin_port = htons( PORT );
ServerAddr.sin_addr.s_addr = inet_addr( "127.0.0.1" );//
记得换IP
memset( &( ServerAddr.sin_zero ), 0, sizeof( ServerAddr.sin_zero ) );
numbytes = sendto( iClientSock, buf, strlen( buf ), 0, ( struct sockaddr * ) & ServerAddr, sizeof( struct sockaddr ) );
printf( "sendto
调用失败!\n" );
printf( "sent %d bytes to %s\n", numbytes, inet_ntoa( ServerAddr.sin_addr ) );
closesocket( iClientSock );
本文转自 帅枫小明 51CTO博客,原文链接:http://blog.51cto.com/576642026/338656,如需转载请自行联系原作者