#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>


void sync( void )
{
  clock_t end = clock () + CLOCKS_PER_SEC/8;
  while (clock() < end) {}
}

int socks[2];
char c;
int stat;




void client_key(void)
{
		while(c!=27)	//mean 27 = ESC
		{
			c = getchar();
			write(socks[1],&c,1);
		}
		exit(0);
}

void server_key(void)
{
	while(c!=27)
	{
		if (listen(socks[0],1))
		{
			read(socks[0],&c,1);
			putchar(c);
		}
		else
		{
			c = 0;
			putchar('\n');
		}
		//sync();
	}
	wait(&stat);
	return;
}

int main (void)
{

	socketpair(AF_UNIX,SOCK_STREAM,0,socks);
	pid_t child = fork();
	
	if (child == 0)	//child
	{
		client_key();
	}
	else				//parent
	{
		server_key();
	}

}
