Skip to content

wa7sa34cx/udp-server-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UDP-Server-CLI

Simple UDP server written in Rust. It receives requests, processes them and sends a responses.

Installation

Prerequisites

Deployment

  1. Fork this repository to your folder
  2. Edit .env.example by putting there your DATABASE_URL
  3. Rename .env.example to .env
  4. Create database with command sqlx database create
  5. Run this command sqlx migrate run. It will create tables in your database add fill them.
  6. Run this command cargo test to run some module tests.
  7. Now, after all these preparations, just execute cargo run from your terminal.

Usage

First of all, start the server with the command:

cargo run

The default port for listening is 8080. You can specify another IP and port for listening:

cargo run -- 127.0.0.1:8888

After starting the server, open a new terminal window. With the help of the Netcat utility, you can send UDP packets to the server. Netcat (nc) command is installed by default in Linux OS. To connect to server using nc command use below command in system terminal:

nc -u 127.0.0.1 8080

Now we can send UDP packet to the server. Here is some requests and responses:

1
one
2
two
3
three
42
Database error: no rows returned by a query that expected to return at least one row
qwerty
Request error: invalid digit found in string

Why did we get these results?

This server accepts the command, validates it and sends a response. If package is a number, it tries to find the text for this ID in the database. The database consists of one table. It has 3 lines by default:

id text
1 one
2 two
3 three

The server also responds with an error if it receives a non-number or no record is found for this number in the database.

License

This project is licensed under the MIT license.

About

Simple UDP server written in Rust

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published