mmo-project/fortran/server
zongor cd803751d9 fix db comments 2023-10-14 09:55:50 -04:00
..
app add readme's, remove testing prints 2023-10-13 22:55:14 -04:00
src fix db comments 2023-10-14 09:55:50 -04:00
test cleanup 2023-10-14 09:32:24 -04:00
README.md add readme's, remove testing prints 2023-10-13 22:55:14 -04:00
fpm.toml add json module 2023-10-10 23:49:28 -04:00
test.sh cleanup 2023-10-14 09:32:24 -04:00

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
  • response

    • array :: records
      • str(24) :: username
      • str(24) :: color
      • double :: x_pos
      • double :: y_pos

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:

  1. listen for connection
  2. read message from client
  3. convert c string to fortran string
  4. convert the fortran string to a json object
  5. run the command from the json object
  6. create a json array of the logged in users and send to client.