#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <assert.h>

#define SIZEOFDATA 10*60

/* Write TEXT to the socket given by file descriptor SOCKET_FD.  */

void read_text (int socket_fd, char* text)
{
  /* Write the number of bytes in the string, including
   *      NUL-termination.  */

  int length = 1;
  write (socket_fd, &length, sizeof (length));

  read (socket_fd, text, SIZEOFDATA);

}

int main (int argc, char* const argv[])
{
  const char* const socket_name = argv[1];
  int socket_fd;
  int counter;
  int j;
  struct sockaddr_un name;
  char  dataToRead[SIZEOFDATA];

  /* Create the socket.  */
  socket_fd = socket (PF_LOCAL, SOCK_STREAM, 0);
  /* Store the server's name in the socket address.  */
  name.sun_family = AF_LOCAL;
  strcpy (name.sun_path, socket_name);
  /* Connect the socket.  */
  connect (socket_fd, (struct sockaddr*)&name, SUN_LEN (&name));
  /* Write the text on the command line to the socket.  */
  read_text (socket_fd, dataToRead);


  
  printf("%s\n",dataToRead);
  
  close (socket_fd);
  return 0;
}


