help in socket programing

Discussion in 'C Programming' started by Clement, Nov 2, 2007.

  1. Clement

    Clement Guest

    Please tell me why the follwing program is not working............


    client.c
    #include<stdio.h>
    #include<sys/socket.h>
    #include<sys/un.h>

    int main()
    {

    int sd, cd, len, re;

    char data[100];

    struct sockaddr_un local, remote;



    sd = socket(AF_UNIX, SOCK_STREAM, 0);


    local.sun_family = AF_UNIX;

    strcpy(local.sun_path, "sock");


    len = sizeof(local.sun_family) + strlen(local.sun_path);

    re = connect(sd, (struct sockaddr *)&local, len);

    scanf("%s",data);
    send(cd, data, strlen(data)+1, 0);
    }


    server.c
    #include<stdio.h>
    #include<sys/socket.h>
    #include<sys/un.h>

    int main()
    {

    int sd, cd, len, re;

    char data[100];

    struct sockaddr_un local, remote;


    sd = socket(AF_UNIX, SOCK_STREAM, 0);



    local.sun_family = AF_UNIX;



    strcpy(local.sun_path, "sock");

    unlink(local.sun_path);

    len = sizeof(local.sun_family) + strlen(local.sun_path);

    re = bind(sd, (struct sockaddr *)&local, len);

    listen(sd, 5);



    cd = accept(sd, (struct sockaddr*)&remote, &len);
    printf("%s",data);
    recv(cd, data, 100, 0);

    printf("%s\n",data);

    }
    Clement, Nov 2, 2007
    #1
    1. Advertising

  2. Clement

    Default User Guest

    Clement wrote:

    > Please tell me why the follwing program is not working............
    >
    >
    > client.c
    > #include<stdio.h>
    > #include<sys/socket.h>
    > #include<sys/un.h>


    There's no support for sockets of any description in standard C. Looks
    like you're working in UNIX, so comp.unix.programmer would be the group
    I'd recommend.




    Brian
    Default User, Nov 2, 2007
    #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. chandu
    Replies:
    3
    Views:
    402
    Matt Humphrey
    Mar 2, 2006
  2. Replies:
    2
    Views:
    1,042
  3. pmm

    Port Delegation in Socket Programing

    pmm, Oct 5, 2006, in forum: C Programming
    Replies:
    1
    Views:
    281
    Walter Roberson
    Oct 5, 2006
  4. Sean
    Replies:
    6
    Views:
    382
    bjeremy
    Jan 16, 2007
  5. Laszlo Nagy
    Replies:
    1
    Views:
    4,817
    Mark Wooding
    Jan 27, 2009
Loading...

Share This Page