Hannes Bock
|
Re: RE: how to send packets over ethernet?
|
Hannes Bock
08/21/2008 6:54 AM
post12167
|
Re: RE: how to send packets over ethernet?
hi,
i tried the "hello world"-udp example and it works fine ... but not for long :o(
after sending about 3000 packtets the bord hangs.
if I put a sleep(1) after sending the first packet i become the only packet which is send.
any idea what's the problem? maybe something with the buffers?
here ist the code:
void myNetwork_thread ()
{
int sock;
struct sockaddr_in sa;
int bytes_sent, buffer_length;
char buffer[200];
int pongcount=1;
sprintf(buffer, "pingpong");
buffer_length = strlen(buffer) + 1;
sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(-1 == sock) /* if socket failed to initialize, exit */
{
printf("Error Creating Socket");
/*return 0;*/
}
sa.sin_family = PF_INET;
sa.sin_addr.s_addr = htonl(0xC0A81E86);
sa.sin_port = htons(7654);
printf("ping");
while(1)
{
bytes_sent = sendto(sock, buffer, buffer_length, 0,(struct sockaddr*) &sa, sizeof(struct sockaddr_in) );
if(bytes_sent < 0)
printf("Error sending packet: %s\n", strerror(errno) );
printf("pong %i\n", pongcount++);
}
close(sock); /* close the socket */
return 0;
}
|
|
|