LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-20-2005, 04:04 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
sockets dont ever send data


Plz take a look at the code in my main function:
Code:
        init_parameters(&parameters);
        parse_config(&parameters);
        send_diff(&parameters,qdisc_stats);
        reset_server((void *)NULL);
        configure((void *)NULL,"add"); /*Configure initially the diffserv */
//      configure((void *)NULL,"change"); /*Configure initially the diffserv */


        sleep(3);
        if (pthread_create(&thread_id[0],NULL,init_diffserv,NULL)>0)
                printf("Error creating thread \n");
        if (pthread_create(&thread_id[1],NULL,reconfigure,NULL)>0)
                printf("Error creating thread \n");


        if (pthread_join(thread_id[0],(void **) p_status) >0)
               perror("Error joining diffserv thread");
        if (pthread_join(thread_id[1],(void **) p_status) >0)
               perror("Error joining reconfigure thread");

        printf("Lalalala");
        return 0;
}
The function send_diff(&parameters,qdisc_stats)is implemented like that

Code:
    void send_diff(struct configuration *diff,union qdisc *qdisc){

        int                     sock,n;
        socklen_t               server_len;
        struct sockaddr_in      server,client;
        struct hostent          *host;

        if (!(host=gethostbyname(DIFFSERV))){ //?? Huge problem how to read value from file
                perror("Client gethostname");
        }
        memset(&server,0,sizeof(server));
        server.sin_family= AF_INET;
        memcpy(&server.sin_addr,host->h_addr,host->h_length);
        server.sin_port=htons((9997));
        if ((sock=socket(PF_INET, SOCK_DGRAM, 0)) < 0){
                perror("Client socket ");
        }
        memset(&client,0,sizeof(client));
        client.sin_family       = AF_INET;
        client.sin_addr.s_addr  = htonl(INADDR_ANY);
        client.sin_port         = htons(9997);

        if ( bind(sock, (struct sockaddr *) &client, sizeof(client)) <0){
                perror("Client bind ");
        }
        server_len=sizeof(server);
        printf("To i exei timi %d \n",i);
        if (sendto( sock, diff , sizeof(struct configuration), 0,(struct sockaddr *) &server, server_len) <0){
                perror("Client send to");
                close(sock);
        }



        if (sendto( sock, qdisc, sizeof(qdisc_stats[10]), 0, (struct sockaddr *) &server, server_len) <0){
                perror("Client send to");
                close(sock);
        }
        printf("Finished sending structs \n");
        close(sock);
}
As u can easily see use two times the sendto system call. Using tcpdump -i eth0 -vvv -n port 9997 (filter for the specific post)
I have noticed that my programme NOT always send packets to the network.. The packets are not created... Firewall is shut down... Sometimes the packets are created and some others not...
What should i do?
 
Old 09-21-2005, 06:59 PM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
How often is "NOT always?" A few packets out of every 100? Every 1000? Every other packet? The UDP protocol isn't guaranteed to deliver packets, and it's not guaranteed to deliver them in order. In my experience, packet loss isn't usually too great on a local network, but it can still occur. If what you are seeing is typical packet loss, and you absolutely cannot lose those packets, you may have to implement some sort of reliability into it by using acks, etc. Or, switch to TCP sockets.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cant send a whole struct with sockets (c code) alaios Programming 9 04-12-2020 09:52 AM
send/recv binary files with C++ sockets dafatdude Programming 3 02-12-2006 08:02 AM
how can i send a file using linux sockets?? crapodino Programming 2 10-09-2005 11:17 PM
Sockets: multiple send() calls throttle server framerate. JCipriani Programming 3 09-22-2005 07:06 PM
First pc sends second dont receive (Sockets problem) Help paul alaios Programming 25 09-22-2005 12:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration