Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

won't able to read on UDP "recvfrom"

Dear friend

i am trying to read an ethernet port using UDP (Code below),

first read operation sucessfully return the read value (which is no of packet to be read) as soon as i enter in to do while loop it will return only one packet read ...and won't go for second read ...!

it won't repeat the loop again....!

please suggest me wher is the problem

where

#define MaxPkt = 1024;

len = sizeof(Servaddress);

retcode = recvfrom(sockid,PktCount1,sizeof(PktCount1),0,(struct sockaddr *) &Servaddress, &len);

if (retcode >0)

printf("\nClient: No. of Packet to be received is: %.d\n\n",PktCount1[0]);

// it will display "No. of Packet to be received is: 7"

do

{

LocalPktCount++;

retcode = recvfrom(sockid,ImgBuff[1],sizeof(ImgBuff[1]),0,(struct sockaddr *) &Servaddress, &len);

if(retcode <= 0) { break; printf("recv call failed"); }

else printf("\n Packet No. received %d\n", LocalPktCount);

Count = 0; // Initilize data address.....

do

{

printf("%c",ImgBuff[1][Count]);

Count++;

}while(Count != MaxPkt);

}while(LocalPktCount != PktCount1[0]+1);

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    In your error checking, you break from the loop before printing the error message. Do it the other way round and see if you get any error message:

    if(retcode <= 0) { printf("recv call failed"); break;}
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    no , there is no error message...but still it display only first packet..not second onward.

    1. can we re-use the ImgBuff[][] again and again for data writing on same location like ImgBuff[0][1448] ...?

    like first i receive the data and write in ImgBuff[0][1448] and then process it and display received data using printf then again receive the new data on same location ImgBuff[0][1448] and again process it display it and again follow the same procedure.

    2. when we create variable like ImgBuff[0][1448] , where it gose i mean where it create (SDRAM,Nios data Cache, etc), because as i increase the buffer size it won't even display the first received packet.

    3. for printing the received data can we use the same variable (ImgBuff[0][1448] ) in which we received the data, or first we copy it in some other variable for printing/display/processing etc.

    4. is printf function affect the received performance..? or due to less priority it won't affect.

    5. Is it possible that printf function skip printing data due to less priority compare to function recvfrom.

    6. Is it possiable to design client/server application without using uc/OS-ii or any other OS. ?