https://github.com/muhammadimran-dev/covid_tcp_server
Covid TCT Server through netcat
https://github.com/muhammadimran-dev/covid_tcp_server
client-server covid covid-19 covid19 golang json server tcp tcp-server
Last synced: 2 months ago
JSON representation
Covid TCT Server through netcat
- Host: GitHub
- URL: https://github.com/muhammadimran-dev/covid_tcp_server
- Owner: muhammadimran-dev
- Created: 2020-07-17T05:45:17.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-08T14:48:15.000Z (over 5 years ago)
- Last Synced: 2024-06-21T17:56:14.314Z (about 2 years ago)
- Topics: client-server, covid, covid-19, covid19, golang, json, server, tcp, tcp-server
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Covid_TCP_Server
Covid TCT Server through netcat
// This program implements a Covid lookup service
// over TCP or Unix Data Socket. It loads CSV Covid Dataset
// information using package lib (see above) and uses a simple
// text-based protocol to interact with the client and send
// the data.
//
// Clients send covid dataset search requests as a textual command in the form:
// Open new Terminal:
// $ go run serertxt.go
// Open another Terminal:
// $ nc localhost 4040
// $ {"query": {"region": "Sindh"}}
// $ {"query": {"date": "4/4/2020"}}
// for query It's mendatory to follow the given JSOn Structure as it is given above.
//
// When the server receives the request, it is parsed and is then used
// to search the list of covid Dataset. The search result is then printed
// JSON Format dataset to the client.
//
// Focus:
// This version of the server uses TCP sockets (or UDS) to implement a simple
// text-based application-level protocol. There are no streaming strategy
// employed for the read/write operations. Buffers are read in one shot
// creating opportunities for missing data during read.
//
// Testing:
// Netcat or telnet can be used to test this server by connecting and
// sending command using the format described above.
//
// Usage: server [options]
// options:
// -e host endpoint, default ":4040"
// -n network protocol [tcp,unix], default "tcp"
Here is complete overview of this tcp server
(Golang): This tasks is designed to help you work with concepts frequently used in backend systems development.
## Programming Language
[Go v1.14](https://golang.org/)
## Task
Write a **TCP Server** that loads dataset from a **CSV file** and provide interface to query the dataset. TCP server will expose port **4040**.
### Dataset
You will be required to download **Corona Virus Pakistan Dataset 2020** from the **OpenData.com.pk**, convert the dataset into a CSV file and use this file to load data into the server.
- Download `COVID_FINAL_DATA.xlsx` from [OpenData.com.pk](https://opendata.com.pk/dataset/corona-virus-pakistan-dataset-2020)
- Convert first sheet "TimeSeries_KeyIndicators" into a CSV file
- Place the CSV file into the repository
Following columns are required in CSV:
- Cumulative Test Positive
- Cumulative Tests Performed
- Date
- Discharged
- Expired
- Admitted
- Region
### Server Communication
User should be able to connect to the server using **NetCat** `nc localhost 4040` command on Linux/Unix based systems.
Once connected to TCP, user should be able communicate with the application by sending queries in JSON format.
```
{
"query": {
"region": "Sindh"
}
}
```
```
{
"query": {
"date": "20/3/2020"
}
}
```
User can query data based on two fields: Region and Date.
In response, server will return a **list** of records that will match query. An individual record's JSON format will look like:
```
{
"date": "2020-03-11",
"positive": 2,
"tests": 171,
"expired": 0,
"admitted": 13,
"discharged": 0,
"region": "Sindh"
}
```
## Query Examples
```
> nc localhost 4040
> {"query": {"region": "Sindh"}}
> {"response": [
{
"date": "11/03/2020",
"positive": 2,
"tests": 171,
"expired": 0,
"admitted": 13,
"discharged": 0,
"region": "Sindh"
},
{
"date": "12/3/2020",
"positive": 14,
"tests": 324,
"expired": 0,
"admitted": 13,
"discharged": 0,
"region": "Sindh"
},
{
"date": "2020-03-13",
"positive": 43,
"tests": 324,
"expired": 0,
"admitted": 12,
"discharged": 0,
"region": "Sindh"
}
]}
```
```
> nc localhost 4040
> {"query": {"date": "2020-03-20"}}
> {"response": [
{
"date": "2020-03-20",
"positive": 2,
"tests": 171,
"expired": 0,
"admitted": 13,
"discharged": 0,
"region": "Sindh"
},
{
"date": "2020-03-20",
"positive": 14,
"tests": 324,
"expired": 0,
"admitted": 13,
"discharged": 0,
"region": "Punjab"
},
{
"date": "2020-03-20",
"positive": 43,
"tests": 324,
"expired": 0,
"admitted": 12,
"discharged": 0,
"region": "KP"
}
]}
```
## Learning Resources
[Effective Go](https://golang.org/doc/effective_go.html)
[Reading a simple CSV in Go](https://medium.com/@ankurraina/reading-a-simple-csv-in-go-36d7a269cecd)
[Read a CSV File into a Struct](https://golangcode.com/how-to-read-a-csv-file-into-a-struct/)
[Go by Example: JSON](https://gobyexample.com/json)
[Network Programming with Go: A TCP Server with a Custom Protocol](https://www.youtube.com/watch?v=yW1ltZidh7g)
[How to Use Netcat Commands: Examples and Cheat Sheets](https://www.varonis.com/blog/netcat-commands/)