Mercurial > hg > beaglert
comparison resources/network/udp-server.c @ 110:fb56681ab1d6 scope-refactoring
Parsing header in udp-server.c
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Wed, 19 Aug 2015 22:36:45 +0100 |
parents | 8c7f537d0a21 |
children | e24c531220ee |
comparison
equal
deleted
inserted
replaced
109:ad8a93cd7c39 | 110:fb56681ab1d6 |
---|---|
45 fromlen = sizeof(struct sockaddr_in); | 45 fromlen = sizeof(struct sockaddr_in); |
46 while (1) { | 46 while (1) { |
47 n = recvfrom(sock,buf,2048,0,(struct sockaddr *)&from,&fromlen); | 47 n = recvfrom(sock,buf,2048,0,(struct sockaddr *)&from,&fromlen); |
48 if (n < 0) error("recvfrom"); | 48 if (n < 0) error("recvfrom"); |
49 printf("Received a datagram of size %d: \n", n); | 49 printf("Received a datagram of size %d: \n", n); |
50 for(i=0; i<n/sizeof(float); i+=8) | 50 printf("Header: channel: %d, timestamp: %d\n", (int)buf[0], (int)buf[1]); |
51 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]); | 51 for(i=2; i<n/sizeof(float); i+=8) |
52 printf("%+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]); | |
52 n = sendto(sock,"Got your message\n",17, | 53 n = sendto(sock,"Got your message\n",17, |
53 0,(struct sockaddr *)&from,fromlen); | 54 0,(struct sockaddr *)&from,fromlen); |
54 if (n < 0) error("sendto"); | 55 if (n < 0) error("sendto"); |
55 } | 56 } |
56 return 0; | 57 return 0; |