How to make the program connect to next IP address without exiting program, if the current connectio

Discussion in 'C Programming' started by Abby, Aug 29, 2003.

  1. Abby

    Abby Guest

    I'm writing a code to send/receive udp packet. I'll receive ip address
    from user (this is the starting ip), then I'll ask user how many ip he
    wants to connect to. For examples:

    Please enter 1st ip: 192.168.0.1
    How many ip do you want to connect to: 10

    Then, my program will create an array to store 10 ip addresses,
    starting from
    192.168.0.1
    ....
    ....
    192.168.0.10

    Then, I'll use each ip to open socket, send udp packet to each ip in
    order. Below is the general idea of what my program does to send and
    receive packet.

    struct resp_pkt * pkt;
    char ip[node][16]; // ip array used to store multiple ip address

    for (i=0;i<node;i++){
    sockfd = open_socket(ip);
    pkt = action(sockfd, udp_pkt);
    if(!pkt) {
    printf("Connection fail\n");
    close(sockfd);
    }
    close(sockfd);
    }

    *** My problem is that if it fail to receive udp packet from any ip
    address, the program will exit, and will not go on to the next ip. How
    can I force it to just send out message and go on to the next ip?? ***

    Right now, when it can't connect to the next ip, it will show error
    message "Connection fail", then exit the program. Anybody has an idea
    how to achieve this? Thank you so much!!!
    Abby, Aug 29, 2003
    #1
    1. Advertising

  2. Abby

    Jack Klein Guest

    On 28 Aug 2003 16:53:17 -0700, (Abby) wrote in
    comp.lang.c:

    > I'm writing a code to send/receive udp packet. I'll receive ip address
    > from user (this is the starting ip), then I'll ask user how many ip he
    > wants to connect to. For examples:


    [snip]

    You need to ask this in a support newsgroup for your particular
    compiler/operating system combination to see what sort of networking
    features it provides. C has no built-in support for any sort of
    networking at all, so it's off-topic here.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c /faq
    Jack Klein, Aug 29, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    407
    Steven Bethard
    Mar 3, 2006
  2. Deniz Bahar
    Replies:
    2
    Views:
    447
    Andrey Tarasevich
    Mar 9, 2005
  3. knguyen
    Replies:
    9
    Views:
    2,805
    Roedy Green
    Feb 15, 2008
  4. Karthi kn
    Replies:
    2
    Views:
    364
  5. Exiting given via next

    , Apr 22, 2009, in forum: Perl Misc
    Replies:
    14
    Views:
    211
Loading...

Share This Page