diff resources/network/udp-server.c @ 93:8c7f537d0a21

edited Scope.h with ifdefs to be compatible with udpio plugin
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 21 Jul 2015 21:18:45 +0100
parents adcb57fd3d75
children fb56681ab1d6
line wrap: on
line diff
--- a/resources/network/udp-server.c	Tue Jul 21 17:17:37 2015 +0100
+++ b/resources/network/udp-server.c	Tue Jul 21 21:18:45 2015 +0100
@@ -23,8 +23,11 @@
    socklen_t fromlen;
    struct sockaddr_in server;
    struct sockaddr_in from;
-   char buf[1024];
-
+   float buf[2048];
+   int i=0;
+   for(i=0; i<2048; i++){
+     buf[i]=0;
+   }
    if (argc < 2) {
       fprintf(stderr, "ERROR, no port provided\n");
       exit(0);
@@ -41,10 +44,11 @@
        error("binding");
    fromlen = sizeof(struct sockaddr_in);
    while (1) {
-       n = recvfrom(sock,buf,1024,0,(struct sockaddr *)&from,&fromlen);
+       n = recvfrom(sock,buf,2048,0,(struct sockaddr *)&from,&fromlen);
        if (n < 0) error("recvfrom");
-       write(1,"Received a datagram: ",21);
-       write(1,buf,n);
+       printf("Received a datagram of size %d: \n", n);
+       for(i=0; i<n/sizeof(float); i+=8)
+	       printf("[%05d]: %+f, %+f, %+f, %+f, %+f, %+f, %+f, %+f\n",i,buf[0+i],buf[1+i],buf[2+i],buf[3+i],buf[4+i],buf[5+i],buf[6+i],buf[7+i]);
        n = sendto(sock,"Got your message\n",17,
                   0,(struct sockaddr *)&from,fromlen);
        if (n  < 0) error("sendto");