#websocket #mongo-db #websocket-server #https #http-server #client-server #enet

app Server_Example

Example Server Using Rocket which has HTTP(S), WebSocket, DB and UDP Support

1 unstable release

0.1.0 Aug 27, 2024

#607 in Database interfaces

AGPL-3.0-only

23KB
218 lines

Example Server

Example Server in Rust Using Rocket

Features

  • HTTP(S)
  • WebSocket
  • Database(MongoDB)
  • UDP(Enet)

Usage

Navigate to the this directory and

cargo run --bin Example_Server
cargo run --bin enet_client

for the server and the enet client. To build

cargo build --release --bin Example_Server
cargo build --release --bin enet_client

build Directory Also has HTTP and HTTPS builds for Windows which runs on localhost 80 and 443 respectively (need manual setup for /db endpoint else you will get [ ]) enet_client.exe is also provided to checkout UDP client which connects to the Server, sends a Client Hello msg and then Disconnect

Note

  • Make Sure The MongoDB is Setup Correctly for Localhost and you Have a database Named DatabaseName and a collection named CollectionName and in documnets you have id (int64) and content (string)
  • You can change them and rebuild as you need, these are just placeholder and only requred if you wanna use the prebuilt binaries
  • Run The Prebuilds in Terminal for Better View
  • Also All the Config of Server is in Rocket.toml and Dependencies in Cargo.toml
  • The log_level is normal by default, if you don't want logs make log_level = "off" in Rocket.toml and build it

DOC

  • /
    • GET: "Server is running"
    • POST: "Server is running"
  • /ws (WebSocket)
    • Messages
      • ping: Server will return a pong
  • /db (Database)
    • GET: Returns the MongoDB Database Documents (need to setup first)
  • /shutdown (UDP Server)
    • POST: Shuts Down the Enet Server which is running in a Different Thread

The documentation for this crate is available at docs.rs.

Dependencies

~39–73MB
~1.5M SLoC