Need suggestion on UDP Concurrent server - Unix

This is a discussion on Need suggestion on UDP Concurrent server - Unix ; Hi All, I am new to the group, i am developing a UDP concurrent server and i want to give the details of that server how it works server: 1) opens a socket 2) bind with well known port and ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Need suggestion on UDP Concurrent server

  1. Need suggestion on UDP Concurrent server

    Hi All,
    I am new to the group, i am developing a UDP concurrent server and i
    want to give the details of that server how it works
    server:
    1) opens a socket
    2) bind with well known port and address
    3) waits for client request in a infinte loop
    a) if the server receives any request it will fork() and the child
    process will process the request

    problems:
    1)The main problem is according to my application i cannot send any
    data to client to the requested port rahter server will send data to
    client waiting on different port.
    2) I am unable to get the client address

    Thanks & Regards
    VDR


  2. Re: Need suggestion on UDP Concurrent server

    On Oct 8, 3:17 am, VDR wrote:

    > 1)The main problem is according to my application i cannot send any
    > data to client to the requested port rahter server will send data to
    > client waiting on different port.


    What? What does that mean? What is a "client waiting of a different
    port"?

    > 2) I am unable to get the client address


    What does that mean?

    Why not paste some commented code or something? Are you calling
    'recvfrom'?

    Why not paste the lines of code you use to call 'recvfrom' and
    'sendto'? You could start out by writing a simple UDP echo server that
    calls 'recvfrom' and immediately uses 'sendto' to send the same data
    back to the same place it received it from.

    If you can't get that to work, paste your code.

    DS


  3. Re: Need suggestion on UDP Concurrent server

    On Oct 8, 5:23 pm, David Schwartz wrote:
    > On Oct 8, 3:17 am, VDR wrote:
    >
    > > 1)The main problem is according to my application i cannot send any
    > > data to client to the requested port rahter server will send data to
    > > client waiting on different port.

    >
    > What? What does that mean? What is a "client waiting of a different
    > port"?
    >
    > > 2) I am unable to get the client address

    >
    > What does that mean?
    >
    > Why not paste some commented code or something? Are you calling
    > 'recvfrom'?
    >
    > Why not paste the lines of code you use to call 'recvfrom' and
    > 'sendto'? You could start out by writing a simple UDP echo server that
    > calls 'recvfrom' and immediately uses 'sendto' to send the same data
    > back to the same place it received it from.
    >
    > If you can't get that to work, paste your code.
    >
    > DS


    Thank you for your response. As you asked i am posting my code
    containg both clent and server side information. when iam running
    client-sever on the same system: i am able to send request to server
    from client and getting response to client , if iam running client and
    server on different systems i am able to send request to client but i
    am unable to get the response from server.




    SERVER SIDE:
    ___________
    /* local address - 201.123.80.218,port=5002*/
    struct in_addr rcvr_addr;
    #ifdef HAVE_INET_ATON
    if (0 == inet_aton(address, &rcvr_addr))
    {
    fprintf(stderr, "%s: cannot parse IP v4 address %s\n",
    argv[0],address);

    exit(1);
    }

    if (rcvr_addr.s_addr == INADDR_NONE)
    {

    fprintf(stderr, "%s: address error", argv[0]);

    exit(1);
    }

    #else

    rcvr_addr.s_addr = inet_addr(address);
    if (0xffffffff == rcvr_addr.s_addr)
    {

    fprintf(stderr, "%s: cannot parse IP v4 address %s\n",
    argv[0],address);


    exit(1);
    }
    #endif

    sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if (sock < 0)
    {

    int err;
    err = errno;
    fprintf(stderr, "%s: couldn't open socket: %d\n", argv[0], err);

    exit(1);
    }

    //name.sin_addr.s_addr = htonl(INADDR_ANY);
    name.sin_addr = rcvr_addr;
    name.sin_family = AF_INET;
    name.sin_port = htons(port);
    if (bind(sock, (struct sockaddr *)&name, sizeof(name)) < 0)
    {
    close(sock);
    fprintf(stderr, "%s: socket bind error\n", argv[0]);
    perror(NULL);
    exit(1);
    }

    for(;
    {
    printf("WAITING FOR CLIENT REQUEST\n");
    recvfrom(sock, (void *)tempbuff, 10, 0, (struct sockaddr *)&cliaddr,
    0);

    cliaddr.sin_port = htons(port+2);


    if(fork()==0)
    {
    printf("CHILD STRATED\n");
    sock_req = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    octets_sent = sendto(sock_req, (void*)&buffer, 0,
    (struct sockaddr *) &cliaddr,sizeof (struct sockaddr_in));
    }
    }




    CLIENT SIDE:
    ____________

    /*server address - 201.123.80.218,port=5002*/
    struct in_addr serv_addr;

    #ifdef HAVE_INET_ATON
    if (0 == inet_aton(address, &serv_addr))
    {
    fprintf(stderr, "%s: cannot parse IP v4 address %s\n", argv[0],
    address);
    exit(1);
    }
    if (rcvr_addr.s_addr == INADDR_NONE)
    {
    fprintf(stderr, "%s: address error", argv[0]);
    exit(1);
    }
    #else
    serv_addr.s_addr = inet_addr(address);
    if (0xffffffff == serv_addr.s_addr)
    {
    fprintf(stderr, "%s: cannot parse IP v4 address %s\n", argv[0],
    address);
    exit(1);
    }
    #endif

    sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if (sock < 0)
    {
    int err;
    err = errno;
    fprintf(stderr, "%s: couldn't open socket: %d\n", argv[0], err);
    exit(1);
    }

    name.sin_addr = serv_addr;
    name.sin_family = AF_INET;
    name.sin_port = htons(port);

    temp=sendto(sock, (void*)tempbuff,10,0, (struct sockaddr *)&name,
    sizeof (struct sockaddr_in));

    printf("%d RQ BYTES SENT----RQ :%s\n",temp,tempbuff);

    sock_req = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if (sock_req < 0)
    {
    int err;
    err = errno;
    fprintf(stderr, "%s: couldn't open socket: %d\n", argv[0], err);
    exit(1);
    }
    name_req.sin_addr.s_addr = htonl(INADDR_ANY);
    name_req.sin_family = AF_INET;
    name_req.sin_port = htons(port+2);

    if (bind(sock_req, (struct sockaddr *)&name_req, sizeof(name_req)) <
    0)
    {
    close(sock);
    close(srtcp_sock);
    close(sock_req);
    fprintf(stderr, "%s: socket bind error\n", argv[0]);
    perror(NULL);
    exit(1);
    }

    if((octets_recvd = recvfrom(sock_req, (void *)&rcvr.message, len, 0,
    (struct sockaddr *)

    NULL, 0))>0)
    {
    printf("%d BYTES RECVD\n",octets_recvd);
    }


+ Reply to Thread