zongor 36579a0784 | ||
---|---|---|
.. | ||
app | ||
src | ||
test | ||
README.md | ||
fpm.toml | ||
test.sh |
README.md
server
The server implementation is as simple as I could make it.
I found a library called mod_dill from the tcp-client-server demo code from a book on modern fortran. This gave me a simple TCP interface to send and recieve "messages".
Originally I had tried saving formatted fortran data into a string and trying to send that, but when you convert the fortran string to a c-string it oftend became garbled and unusable when sent through the tcp connection so I stopped using that method.
I found in fpm official registry a json library which would make it much easier to deal with data transfer.
The simplest way to implement the communcation between the server and clients would be a series of tcp requests and responses.
-
request
- int :: request_type
- ping # 0
- login # 1
- logout # 2
- move # 3
- str(24) :: username
- double :: x_pos
- double :: y_pos
- int :: request_type
-
response
- array :: records
- str(24) :: username
- str(24) :: color
- double :: x_pos
- double :: y_pos
- array :: records
For each request, the same response is returned with is a list of the logged in users.
The commands that can be sent to the server are logging in, logging out, moving, and the default "ping" which is essentially a noop from the servers pov.
The server uses the same sqlite library as the www implementation.
The server loop is:
- listen for connection
- read message from client
- convert c string to fortran string
- convert the fortran string to a json object
- run the command from the json object
- create a json array of the logged in users and send to client.