Skip to content

codinbytes/Covid-TCP_Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

Reading a simple CSV in Go

Read a CSV File into a Struct

Go by Example: JSON

Network Programming with Go: A TCP Server with a Custom Protocol

How to Use Netcat Commands: Examples and Cheat Sheets

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages