Please do help me find out what i am doing wrong..
Im doing a network listening program using Winsock which constantly listen for datagrams.. my recever thread is able to receve data using recvfrom() but in certain situation when it receves data from multiple streams into that socket, some datagrams are found missing(no fail return from recvfrom() though) while i can still see them using network monitoring tools like NetMon and wireshark.
the protocol is UDP, i set MTU size of 1500 for the recvfrom() buffer and also tried increasing it to 5000 with no luck.. i tried blocking and unblocking modes also. help me figure out what i'm really missing here and why i'm missing packets. interestingly recvfrom never fails too..
here's a snippet of my receiving code.
Code:
.
.
SOCKET RecvSocket;
sockaddr_in RecvAddr;
unsigned short u_listenport = 6088;
.
.
RecvSocket = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
if( RecvSocket == INVALID_SOCKET )
{
printf( "SOCKET ERROR.\n" )
return;
}
RecvAddr.sin_family = AF_INET;
RecvAddr.sin_port = htons( u_listenport );
RecvAddr.sin_addr.s_addr = htonl( "192.135.0.1" );
if( bind( RecvSocket, (SOCKADDR *) &RecvAddr, sizeof(RecvAddr) ) != 0 )
{
printf( "BIND Failed.\n" );
closesocket( RecvSocket );
WSACleanup();
return;
}
and, the following code runs in a seperate thread.
Code:
void FunctorListenUDP( void *argptr )
{
char RecvBuf[1500];
while( !b_quit )
{
memset( RecvBuf, 0, 1500 );
int result = recvfrom( RecvSocket, RecvBuf, 1500, 0, (SOCKADDR*) &SenderAddr, &SenderAddrSize );
if( result == SOCKET_ERROR)
{
printf( "SOCKET Error in recvfrom.\n" )
continue;
}
my_app_callback_for_data( RecvBuf, result );
}
closesocket( RecvSocket );
WSACleanup();
}
please help me solve this problem, this is a confusing problem and i'm not very wellinto winsock programming. i tried many things myself before posting this here. thanks in advance. :)
Re: Please do help me find out what i am doing wrong..
did you ever read something about UDP protocol? For instance in wiki:
Quote:
UDP provides an unreliable service and datagrams may arrive out of order, appear duplicated, or go missing without notice. UDP assumes that error checking and correction is either not necessary or performed in the application, avoiding the overhead of such processing at the network interface level.
So what do you expect? :confused:
Note also that the most of network Admins just forbid using UDP.
Re: Please do help me find out what i am doing wrong..
@VictorN
First of all, thank you for your reply. I know about that scenario of unreliable transport mechanism of UDP. but i'm able to see those "missing" packets captured by NetMon and wireshark(ethreal).. but recvfrom is not receiving those datagrams.. and no error case is returened as well.. its just, plainly missing!... is there anything wrong with my piece of code.. did i missed anything..