#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>

#define EXIT 4

void error(char *);

struct sockaddr_un serv_addr;
int new_sd,servlen;

int main(int argc, char **argv)
{
char buf[40];
	
	new_sd = socket(AF_UNIX, SOCK_STREAM, 0);
	if(new_sd<0)
	{	error("sfalma sth dhmioyrgia toy socket");	}

	bzero((char *)&serv_addr,sizeof(serv_addr));
	 
	serv_addr.sun_family = AF_UNIX;

	strcpy(serv_addr.sun_path, "mysock");
	
	servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family);
	
	if (connect(new_sd, (struct sockaddr *) &serv_addr, servlen) < 0)
       	{	error("sfalma sundesis toy client me ton server");	}
	int op = 4;
	
	
	write(new_sd,&op,sizeof(int));
	
	write(new_sd,&argc,sizeof(int));	// auto to stelnw ston server gia naxerei poso(megetos) ta diabasei
	
	int i = 1;
	for (i = 1; i < argc; i++)
	{
		int size = strlen (argv[i]) + 1;
		write (new_sd, &size, sizeof(int));
		
		write (new_sd, argv[i], size);
		
	}
	printf("Ta dedomena stalthikan\n");
	//int status;
	//read (sd, &status, sizeof(int));
	//return status;

}



void error(char *msg)
{
    perror(msg);
    exit(0);
}
