私は次の関数を作成し、正常に動作します。
int NetworkSocket::readDatagrams(unsigned char *buffer, string &srcAddress, unsigned short int & srcPort,size_t frameSize)
{
unsigned int maximumPacketSize = sizeof(buffer);//frameSize ;
int returnValue ;
sockaddr_in from;
socklen_t fromLength = sizeof( from );
int receivedBytes;
fromLength = sizeof(this->getSocketAddressStructureOfServer());
receivedBytes = recvfrom( this->socketFD, buffer, maximumPacketSize, 0, (sockaddr *)&this->getSocketAddressStructureOfServer(), &fromLength ) ;
cout << receivedBytes << endl;
returnValue = receivedBytes;
if ( receivedBytes <= 0 )
returnValue = -1;
/// exporting data
//
srcAddress = inet_ntoa(this->getSocketAddressStructureOfServer().sin_addr);
srcPort = ntohs( ( unsigned short int)this->getSocketAddressStructureOfServer().sin_port );
return returnValue;
}
適用すると、ref srcAddressとportに戻ります。バッファがいっぱいですが、printfバッファができません。どうすればよいですか?wirehakr show 000010001これは5バイトを意味し、それを調べてデータと比較する必要があります。