-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram.c
54 lines (35 loc) · 937 Bytes
/
program.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <ProcessingUnit.h>
#include "program.h"
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <unistd.h>
// Test on Linux: Sockets:
// echo " 2hi" | nc -U socketfile
// Test on Linux: TCP:
// echo " 2hi" | nc 127.0.0.2 32343
void Program(ProcessingUnitServerStructure *pu){
ByteArrayReference message;
char c;
// Wait for and receive next request:
ServerReceive(pu, &message);
// Print message:
printf("Server got: \n");
for(int i = 0; i < message.byteArrayLength; i++){
printf("%c", (char)message.byteArray[i]);
}
printf("\n");
// Convert to upper case.
for(int i = 0; i < message.byteArrayLength; i++){
c = (char)message.byteArray[i];
if(c >= 'a' && c <= 'z'){
c = c - 'a' + 'A';
}
message.byteArray[i] = c;
}
// Respond:
ServerSend(pu, message.byteArray, message.byteArrayLength);
sleep(1);
}