Mozda je ovo vise za C/C++ ali evo:
klijent :
Code:
#include<sys/types.h>
#include<sys/socket.h>
#include<sys/un.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
int main(){
int sockfd,new_fd;
char gg[1024];
struct sockaddr_un sun;
socklen_t len=sizeof(struct sockaddr_un);
sockfd=socket(AF_UNIX,SOCK_STREAM,0);
strcpy(sun.sun_path,"/tmp/root_ipc");
sun.sun_family=AF_UNIX;
connect(sockfd,(struct sockaddr *)&sun,len);
write(sockfd,"I'm cool socketn",16);
close(sockfd);
}
i server :
Code:
#include<sys/types.h>
#include<sys/socket.h>
#include<sys/un.h>
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<signal.h>
void handler(int sig){
unlink("/tmp/root_ipc");
exit(0);
}
int main(){
int sockfd,new_fd;
char gg[1024];
struct sockaddr_un sun;
socklen_t len=sizeof(struct sockaddr_un);
signal(SIGINT,handler);
sockfd=socket(AF_UNIX,SOCK_STREAM,0);
strcpy(sun.sun_path,"/tmp/root_ipc");
sun.sun_family=AF_UNIX;
bind(sockfd,(struct sockaddr *)&sun,len);
chmod("/tmp/root_ipc",0777);
listen(sockfd,10);
while (1){
new_fd=accept(sockfd,(struct sockaddr *)&sun,&len);
read(new_fd,gg,1024);
printf("%s",gg);
close(new_fd);
}
close(sockfd);
unlink("/tmp/root_ipc");
}