2016-11-03 22:44:35 +01:00
|
|
|
#include "../lib/communication.h"
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
|
|
|
|
#define PONGD_SERVICE_NAME "pongd"
|
|
|
|
#define LISTEN_BACKLOG 50
|
|
|
|
#define handle_error(msg) \
|
|
|
|
do { perror(msg); exit(EXIT_FAILURE); } while (0)
|
|
|
|
|
|
|
|
int main(int argc, char * argv[]) {
|
|
|
|
char *srv_message = malloc(1024);
|
|
|
|
char *pidfile = malloc(1024);
|
|
|
|
char *buffer = malloc(1024);
|
|
|
|
|
|
|
|
snprintf(srv_message , 1024, "%s %d 1 1" ,"connect 127.0.0.1 6000" , getpid());
|
|
|
|
snprintf(pidfile, 1024,"%s%d-1-1", "/tmp/ipc/", getpid());
|
|
|
|
|
|
|
|
char *proc_message = "hello frero";
|
|
|
|
|
|
|
|
int sfd;
|
|
|
|
struct sockaddr_un my_addr;
|
|
|
|
socklen_t peer_addr_size;
|
|
|
|
|
|
|
|
sfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
if (sfd == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
memset(&my_addr, 0, sizeof(struct sockaddr_un));
|
|
|
|
// Clear structure
|
|
|
|
my_addr.sun_family = AF_UNIX;
|
|
|
|
strncpy(my_addr.sun_path, "/tmp/ipc/tcpd", sizeof(my_addr.sun_path) - 1);
|
|
|
|
|
|
|
|
peer_addr_size = sizeof(struct sockaddr_un);
|
|
|
|
if(connect(sfd,(struct sockaddr *) &my_addr, peer_addr_size) == -1)
|
|
|
|
{
|
|
|
|
perror("connect()");
|
|
|
|
exit(errno);
|
|
|
|
}
|
2016-11-04 16:51:17 +01:00
|
|
|
//printf("connected...\n");
|
2016-11-03 22:44:35 +01:00
|
|
|
file_write(sfd, srv_message, strlen(srv_message));
|
2016-11-04 16:51:17 +01:00
|
|
|
//printf("%s\n", proc_message);
|
|
|
|
//sleep(1);
|
|
|
|
file_write(sfd, proc_message, strlen(proc_message));
|
2016-11-03 22:44:35 +01:00
|
|
|
file_read(sfd, &buffer);
|
|
|
|
printf("%s\n", buffer);
|
2016-11-04 16:51:17 +01:00
|
|
|
//sleep(1);
|
2016-11-03 22:44:35 +01:00
|
|
|
file_write(sfd, "exit", 4);
|
|
|
|
|
|
|
|
close(sfd);
|
|
|
|
|
|
|
|
// //sleep(1);
|
|
|
|
// cfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
// if (sfd == -1)
|
|
|
|
// return -1;
|
|
|
|
// strncpy(my_addr.sun_path, pidfile, sizeof(my_addr.sun_path) - 1);
|
|
|
|
// if(connect(cfd,(struct sockaddr *) &my_addr, peer_addr_size) == -1)
|
|
|
|
// {
|
|
|
|
// perror("connect()");
|
|
|
|
// exit(errno);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// close(cfd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|