Commit 4eb78040 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Reduce output. Send multiple packets.

parent 1a0866a7
......@@ -12,13 +12,11 @@ void *receive_loop(void *ptr) {
char bufin[MAX_PAYLOAD_LENGTH];
prrt_socket *sock_ptr = ptr;
printf("RECEIVING:\n");
while(1) {
memset(bufin, 0, MAX_PAYLOAD_LENGTH);
prrt_packet *t = prrt_recv_feedback(sock_ptr, bufin, MAX_PAYLOAD_LENGTH);
if(t != NULL) {
print_packet(t);
delete_packet(t);
}
usleep(1000);
......@@ -89,18 +87,16 @@ int prrt_connect(prrt_socket *sock_ptr, char *host, uint16_t port) {
}
int prrt_send(prrt_socket *sock_ptr, const void *data, size_t data_len) {
prrt_packet packet;
create_packet_data(&packet, 5, data, data_len);
// TODO: finally delete_packet(packet);
int res = 0;
prrt_packet* packet = malloc(sizeof(prrt_packet));
create_packet_data(packet, 5, data, data_len);
uint8_t buf[MAX_PAYLOAD_LENGTH];
uint32_t length = packet_size(&packet);
if(encode_packet(buf, MAX_PAYLOAD_LENGTH, &packet) < 0) {
uint32_t length = packet_size(packet);
if(encode_packet(buf, MAX_PAYLOAD_LENGTH, packet) < 0) {
perror("BUF too small.");
return -1;
}
print_packet(&packet);
// SENDING TO ALL RECEIVERS
int i;
......@@ -119,10 +115,12 @@ int prrt_send(prrt_socket *sock_ptr, const void *data, size_t data_len) {
if((sendto(sock_ptr->fd_data, buf, length, 0, (struct sockaddr *) &targetaddr, sizeof(targetaddr)) < 0)) {
perror("sendto failed");
return -1;
res = -1;
break;
}
}
return 0;
delete_packet(packet);
return res;
}
prrt_packet *prrt_recv(prrt_socket *sock_ptr) {
......
......@@ -5,6 +5,7 @@
#include "prrt/socket.h"
int main(int argc, char* const argv) {
int i;
if(argc != 1) {
printf("Too few arguments.\n");
}
......@@ -27,8 +28,11 @@ int main(int argc, char* const argv) {
prrt_connect(&sock, remote_host2, remote_port2);
printf("SENDING\n");
char *message = "this is a message";
prrt_send(&sock, message, strlen(message));
for(i= 0; i < 5; i++) {
char *message = "this is a message";
prrt_send(&sock, message, strlen(message));
}
usleep(5000*1000);
prrt_close_socket(&sock);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment