Giter VIP home page Giter VIP logo

tcp-ip-client's Introduction

TCP/IP Client

A simple tcp/ip client that sends a request containing the filename to the server to be transferred to the client

Project structure

At present, all the source files are within a single directory called Src to keep things simple. Though at some point it'd be better to split the header and source files into two seperate folders e.g. include and src.

Client Configuration

In main.h

#define PORT 12345                        // Server port to connect to
#define FILE_NAME_SIZE_MAX 32 + 1         // Maximum size supported for the requested filename
#define FILE_DOWNLOAD_TABLE "/home/vinay_divakar/file_download" // file download path
#define FILE_DOWNLOAD_PATH_NAME_SIZE_MAX 64 // Maximum size supported for the file path

Building the project

  1. In the Makefile, update the SRCDIR variable to point the path project is located on your local machine.
SRCDIR = /home/vinay_divakar/tcp-ip-client/src
  1. Run make from within the project's root i.e.tcp-ip-client to build your project. This will generate an executable called client_app.

Running the application

  1. Run the client_app executable with the filename to request for. Ensure the file name is not greater than FILE_NAME_SIZE_MAX. And application only supports a single input arg.
vinay_divakar@vinay-divakar-Linux:~/Server$ ./client_app <filename> 
  1. For debug purposes or visiblity, you can enable/uncomment the below line in main.c within the function file_download(). This prints what's being received from the sever.
// enable to whats being received from the server
// printf("recv: %.*s\r\n", err, (char *)buffer);

How it works

The client does the follow:

  1. Reads the arg from command-line.
  2. Sets up the socket and connects to the server.
  3. Sends the request to the server i.e. .
  4. Configures the socket to recieve in non-blocking mode and enable receiving POLLIN events.
  5. Polls of socket read events.
  6. On a read event, receives the data and prints it on the terminal(if enabled).
  7. TBD: store the contents to the file / download.

Things to be implemented

  1. Download Receievd File Contents

The receievd file contents from the server needs to written to a file for download on the loacal machine. On receiving the first response from the server, create a file with the requested and write the contents to it with start offset 0. On a successful writes, add the number of bytes written to the file to a which can be used as start offset for subsequent writes. Keep doing this until we have received the eof indication from the server. Another better way about this is to get the size of the file to be download from the server and use that to determine the progress of the download.

  1. Tidy up

Functions are all over the place in main and needs to be tidied up and better organized.

tcp-ip-client's People

Contributors

deeplyembeddedwp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.