By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,743 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,743 IT Pros & Developers. It's quick & easy.

help in socket programing

P: n/a
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);

}

Nov 2 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
Nov 2 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.