Mercurial > hg > beaglert
comparison 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 |
comparison
equal
deleted
inserted
replaced
92:a55dcdcebdcd | 93:8c7f537d0a21 |
---|---|
21 { | 21 { |
22 int sock, length, n; | 22 int sock, length, n; |
23 socklen_t fromlen; | 23 socklen_t fromlen; |
24 struct sockaddr_in server; | 24 struct sockaddr_in server; |
25 struct sockaddr_in from; | 25 struct sockaddr_in from; |
26 char buf[1024]; | 26 float buf[2048]; |
27 | 27 int i=0; |
28 for(i=0; i<2048; i++){ | |
29 buf[i]=0; | |
30 } | |
28 if (argc < 2) { | 31 if (argc < 2) { |
29 fprintf(stderr, "ERROR, no port provided\n"); | 32 fprintf(stderr, "ERROR, no port provided\n"); |
30 exit(0); | 33 exit(0); |
31 } | 34 } |
32 | 35 |
39 server.sin_port=htons(atoi(argv[1])); | 42 server.sin_port=htons(atoi(argv[1])); |
40 if (bind(sock,(struct sockaddr *)&server,length)<0) | 43 if (bind(sock,(struct sockaddr *)&server,length)<0) |
41 error("binding"); | 44 error("binding"); |
42 fromlen = sizeof(struct sockaddr_in); | 45 fromlen = sizeof(struct sockaddr_in); |
43 while (1) { | 46 while (1) { |
44 n = recvfrom(sock,buf,1024,0,(struct sockaddr *)&from,&fromlen); | 47 n = recvfrom(sock,buf,2048,0,(struct sockaddr *)&from,&fromlen); |
45 if (n < 0) error("recvfrom"); | 48 if (n < 0) error("recvfrom"); |
46 write(1,"Received a datagram: ",21); | 49 printf("Received a datagram of size %d: \n", n); |
47 write(1,buf,n); | 50 for(i=0; i<n/sizeof(float); i+=8) |
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]); | |
48 n = sendto(sock,"Got your message\n",17, | 52 n = sendto(sock,"Got your message\n",17, |
49 0,(struct sockaddr *)&from,fromlen); | 53 0,(struct sockaddr *)&from,fromlen); |
50 if (n < 0) error("sendto"); | 54 if (n < 0) error("sendto"); |
51 } | 55 } |
52 return 0; | 56 return 0; |