Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with recieveing sockets

Status
Not open for further replies.

farklem

Technical User
Feb 5, 2003
16
US
Ok, I am writing an xbox program that recieves a list of items from a PC application through a UDP socket connection. Each item of the list is sent separately. I have created this thread that constantly listens for the list. The problem is that when the list is longer than around 120 items I get this error: "[XONLINE] udpWarn: [D00212C8] Receive buffer is full (16466 bytes). UDP packet plus 3 data bytes lost." I know that UDP is not very reliable but when the list is say 100 items I have never had it drop a packet.

#define MAXBUFLEN 1000
DWORD __stdcall ListenerThread( void* listen )
{
WSADATA WsaData;
int iResult = WSAStartup( MAKEWORD(2,2), &WsaData );
if( iResult != NO_ERROR )
Debug("Error at WSAStartup");

int sockfd;
struct sockaddr_in my_addr; // my address information
struct sockaddr_in their_addr; // connector's address information
int addr_len, numbytes;

if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
Debug("Socket Creation Error");

my_addr.sin_family = AF_INET; // host byte order
my_addr.sin_port = htons(8604); // short, network byte order
my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP
memset(&(my_addr.sin_zero), '\0', 8); // zero the rest of the struct

if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1)
Debug("Bind Error");

addr_len = sizeof(struct sockaddr);
char* xrec = (char*)malloc(MAXBUFLEN);
while(true)
{
if ((numbytes=recvfrom(sockfd, xrec, MAXBUFLEN-1, 0, (struct sockaddr *)&their_addr, &addr_len)) == -1)
Debug("Recieve Error");
xrec[numbytes] = '\0';
}

return 0;
}
 
Well, after several days of trying to figure this out I have come to realize that this code is just fine. The problem was the default buffer size on the xbox. I hope someone can at least find this useful. The paramater: cfgSockDefaultRecvBufsizeInK was the problem because by default it is set to 16K so I upped it to 64 just to be safe. Now everything works well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top