发送UDP数据

int SendUDPMsg( const char* pPeerIP, unsigned short int nPort, const void* pData, size_t n )
{
SOCKET s = socket( AF_INET, SOCK_DGRAM, 0 );
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons( nPort );
addr.sin_addr.s_addr = inet_addr( pPeerIP );
connect( s, (struct sockaddr*)&addr, sizeof(addr) );
send( s, (char*)pData, n, 0 );
closesocket( s );
return 0;
}

你可能感兴趣的:(发送UDP数据)