Hello,
I have a question about socket programming
The question was a homework of this university of past (2011?) course.
The server is simulating a sensor that provides readings of temperature, light and humidity ( temp.dat, light.dat, humid.dat
) each with single column of number, one per row.
temp.dat:
60
59
58
57
......
light.dat:
40
50
20
30
......
humid.dat:
1
2
3
4
......
The server will open each file, read in all sensor values, and serve every request from the client. If a client requests temperature, the server will return a certain temperature sample from temp.dat
according to the time of the connection. Starting from the first value of temp.dat
when a connection is established, every second the server should return the next value in temp.dat
upon request. If EOF is reached, the server should wraps around and start from the beginning of the file again. Display readings to the screen:
Connected to server!
Data returned by the server:
TEMPERATURE = 60 HUMIDITY = 40 LIGHT = 1
Data returned by the server:
TEMPERATURE = 59 HUMIDITY = 50 LIGHT = 2
Data returned by the server:
TEMPERATURE = 58 HUMIDITY = 20 LIGHT = 3
...... ...... ......
I have attached the code in C for server and client parts, but I am quite obscure about reading the 3 files in the server side and display in the client side by request.
This is NOT my homework for any class, but for self study to understand basic server-client communication of socket programming in C.
Any suggestion is greatly appreciated and pseudo code is fine.
Thanks a lot!