Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > help in socket programing

Reply
Thread Tools

help in socket programing

 
 
Clement
Guest
Posts: n/a
 
      11-02-2007
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);

}

 
Reply With Quote
 
 
 
 
Default User
Guest
Posts: n/a
 
      11-02-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
HEEELLLPPP socket programing instant messaging Sean C++ 6 01-16-2007 07:28 PM
Using SOcket programing to create multiple clients conatcting a single server zigbeedeep@gmail.com Java 2 11-12-2006 04:08 PM
Port Delegation in Socket Programing pmm C Programming 1 10-05-2006 07:43 AM
doubt about socket programing chandu Java 3 03-02-2006 01:46 PM



Advertisments