static PyObject* repaClose(PyObject* self, PyObject *args) {
	repa_sock_t sock;

	if (PyArg_ParseTuple(args, "(ii)", &sock.sock_send, &sock.sock_recv)) {
		repa_close(sock);
	} else {
		PyErr_SetString(RepaError, "Error on read parameters");
		return NULL;
	}

	Py_RETURN_NONE;
}
int main(){
    char *interest,*data;

    sock = repa_open();

    //Aloca espaço para registrar endereço e dados para transmissão
    interest = (char*)malloc(255*sizeof(char));
    data = (char*)malloc(1500*sizeof(char));

    strcpy(interest,"client");
    repa_register_interest(sock,interest); // Registra o interesse

    while (true){
        getTemperature(data);
        sendMessage(data);
        sleep(1);
    }
    free(interest);
    free(data);
    repa_close(sock);
    return 0;
}
Example #3
0
int main(int argc, char** argv) {
    char *aux;
	int opt;
	repa_sock_t sock;
	static int send_or_recv = -1, wait_time = 0;
	const char *interest = "repa-test://speed";
	size_t packet_size = PACKET_SIZE, num_packets = 1000;

	while (1) {
		static struct option long_options[] = {
				/* These options set a flag. */
				{"send", no_argument, &send_or_recv, APP_SEND},
				{"receive", no_argument, &send_or_recv, APP_RECV},
				{"wait-time", no_argument, &wait_time, 1},
				{"help", no_argument, 0, 'h'},
				{"packet-size", required_argument, 0, 'p'},
				{"num-packet", required_argument, 0, 'n'},
				{0, 0, 0, 0}
		};
		/* getopt_long stores the option index here. */
		int option_index = 0;

		opt = getopt_long (argc, argv, "hn:p:", long_options, &option_index);

		/* Detect the end of the options. */
		if (opt == -1)
			break;

		switch(opt) {
		case 0:
			/* If this option set a flag, do nothing else now. */
			if (long_options[option_index].flag != 0)
				break;
			printf ("Option %s", long_options[option_index].name);
			if (optarg)
				printf (" with arg %s", optarg);
			printf ("\n");
			break;
		case 'n':
			num_packets = atol(optarg);
			break;
		case 'p':
			packet_size = atol(optarg);
			break;
		case 'h':
		default:
			aux = strrchr(argv[0], '/');
			usage((aux[0] == '/' ? aux+1: aux));
			exit(EXIT_SUCCESS);
		}
	}

	if ((sock = repa_open()).error < 0) {
		printf("ERROR: Cannot open repa socket!\n");
		exit(EXIT_FAILURE);
	}

	repa_register_interest(&sock, interest);

	if (send_or_recv == APP_SEND) {
			calc_send(&sock, interest, packet_size, wait_time, num_packets*packet_size);
	} else if (send_or_recv == APP_RECV) {
			calc_recv(&sock);
	} else {
		printf("You need specify if you want \"send\" or \"receive\" packets\n");
	}

	repa_close(&sock);

	return EXIT_SUCCESS;
}