help in socket programing

C

Clement

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);

}
 
D

Default User

Clement said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top