int main(int argc, char **argv) {

  struct sockaddr_in servaddr;
  int *sock;
  int size;
  int size_sent;
  sock = (int*)malloc(sizeof(int));
  sock[0] = socket(AF_INET, SOCK_STREAM, 0);

  memset(&servaddr, 0, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(6791);
  servaddr.sin_addr.s_addr = inet_addr("10.0.18.36");
  connect(sock[0], (struct sockaddr *)&servaddr, sizeof(servaddr));
  receive_answer(sock);
  command_header cmmd;
  size = status_command_answer(&cmmd);
  size = var_read_command_ask(&cmmd);
  cmmd.p[0] = 0x01;
  while(1) {
    	
    //char message[161];
    //fgets(message, 161, stdin);
		/* Replacing '\n' with '\0' */
    //char *tmp = strchr(message, '\n');
    //if (tmp) *tmp = '\0';

		//scanf(" %s", message);
    if(size_sent = send(sock[0], &cmmd, size, 0)>0)
      printf("Sent %d bytes correctly\n",size_sent);
    sleep(10);
  }

    //close(sock);
}
Exemple #2
0
int client (int argc, char * argv[]) {
	//printf("starting client\n");
	int i;
	unsigned long int id;
	char myMailbox[MAILBOX_SIZE];
	char primary[MAILBOX_SIZE]; // when we use the decentrlized solution, the client send its request to the first-primary. (However the code is the same, we just change in the xml file the identity of the primary by the identity of the first-primary)

	if (argc != 3) {
		//printf("here in the client\n");
		exit(1);
	}

	id = atoi(argv[1]);
	sprintf(myMailbox, "client-%ld", id);
	// the name of the primary is known by the client
	strcpy(primary, argv[2]);

	srand(time(NULL) * id + MSG_get_clock());

	for (i = 0; i < nb_requests; i++) {
		MSG_process_sleep(((double)(rand () % 1000001)) / 1000.0);
		
		//send a request to the primary
		send_task(i, primary, myMailbox);		

		// wait for the result of the request before sending an other one
		receive_answer(myMailbox);
	}
	
	// signal to the primary that there is no more tasks to treat for that client
	//printf("%s: I send finalize\n", myMailbox);
	send_finalize(primary);

	return 0;
}
/*
 ****************************************************************
 *	Domain name resolver					*
 ****************************************************************
 */
void
main (int argc, const char *argv[])
{
	int			opt;
#if (0)	/*******************************************************/
	SERVTB			*sp;
	int			index;
#endif	/*******************************************************/
	INADDR			server_addr;
	T_BIND			bind;

	/*
	 *	Pequena inicialização
	 */
	error_msg_to_log++;

	/*
	 *	Verifica se é SUPERUSUÁRIO
	 */
	if (geteuid () != 0)
		error ("$O usuário efetivo não é SUPERUSUÁRIO");

	/*
	 *	Analisa as opções
	 *
	 *	Sintaxe:
	 *		port_daemon [-v] <port_server_addr> ...
	 */
	while ((opt = getopt (argc, argv, "v")) != EOF)
	{
		switch (opt)
		{
		    case 'v':			/* Verbose */
			vflag++;
			break;

		    default:			/* Erro */
			putc ('\n', stderr);
			help ();

		}	/* end switch */

	}	/* end while */

	argv += optind;
	argc -= optind;

#if (0)	/*******************************************************/
	if (argc == 0)
		help ();
#endif	/*******************************************************/

	/*
	 *	Abre os "endpoint"s
	 */
	if ((udp_fd = t_open (udp_dev, O_RDWR, (T_INFO *)NULL)) < 0)
		error ("$*Não consegui abrir \"%s\"", udp_dev);

	/*
	 *	Obtém a porta local
	 */
	server_addr.a_port = PMAP_PORT;
	server_addr.a_addr = 0;

	bind.addr.len	 = sizeof (INADDR);
	bind.addr.maxlen = sizeof (INADDR);
	bind.addr.buf	 = &server_addr;

	if (t_bind (udp_fd, &bind, &bind) < 0)
		error ("$*Não consegui dar \"t_bind\" UDP");

	send_req ();

	receive_answer ();

#if (0)	/*******************************************************/
	/*
	 *	Cria um filho para enviar os pedidos de DNS.
	 *	O pai le os datagramas de resposta.
	 */
	if ((pidfilho = thread ()) < 0)
		error ("$*Não consegui criar um novo processo");

	if (pidfilho > 0)
		pai ();
	else
		filho ();

	/* Não retorna */
#endif	/*******************************************************/

}	/* end port_mapper */