Coder Social home page Coder Social logo

tcp-protocol's Introduction

TCP File Transfer protocol

Description.

TCP file transfer protocol is a project to demostrate how the TCP protocol works, we implemented three objects which communicate through TCP sockets: client.py server.py and stammerProxy.py. For this project we developed a custom protocol, all messages must be send with this specific format. On This implementation only two functions are available: get to a get a file from the server and put to send a file to the server.

How it Works.

Altough all three objects are part of the protocol we will only describe two: client.py and server.py

The client is the one that initialize all communication, it send the first request to server. The request can be a get or a put; in the case of a get, the client will send a first message containing the action and a file name. The server will receive the request and it will response with the appropiate text for the requested file. For a put request, same as before the client sends the first messages but in this ocassion it sends the full message incluiding the content of the file. The server will receive the message and it will identify that the client sent a put request which means that the server needs to save in a local file all the data that the client sent. All the messages between client and server must follow a format (we will discuss the format later).

As mentioned before the client can only send two types of messages: get and put.

  • get: the client sends a request to get a file from the server, the file will be store in a local copy within the current directory.
  • put: the client sends a request to save a file into the server, the fille will be store in a local copy on the server within the current directory.

Multiple clients.

The server can receive multiple clients, the functionality of receiving multiples clients it just to demostrate that our server can handle and process multiple connections. The way we implemented our client, make the idea of multiple a little messy. To avoid race conditions and to make thing simpler each local copy is save by appending the client id at the beginning, this means that if the server received 3 connections it will create three files: 0filename.txt (client 1), 1filename.txt (client 2), and 3filename.txt (client 3).

Functions.

Client and server have the same sets of function, they work in a similar way with the only difference that the client is the one that initiates the communication.

  • send: send a message, it can be a request or a response. Must use protocol format
  • receive: receive incomming messages, client and server will keep reading until the full messages gets delivered
  • check read/write: by using a select client and server keeps listening for any change on the socket. The socket can be ready to read or to write.

Message Format.

Our TCP protocol use a custom protocol, all messages must follow the format otherwise the server and client won't be able to process messages. The protocol is delimiter by ":"

Example get request

Message's Lenght : Type : Text Lengt : Text
24 : get : 16 : declaration.txt

Running Examples:

To run the TCP protocol you need to execute all objects,

  • First you need to start the server and proxy.

  • pyhton stammerProxy.py -d

  • cd server and then python server.py -d

  • Then you need to execute the client.

  • cd ../

  • pythong client.py -d -g declaration.txt

The following images shows our client sending a file to the server, the communication between the client and server goes through the stammer proxy. Example

Multiple clients sending a file.

Multiple Clients

Test Script.

We created a test script Test Script which can help to reduce the testing setup, the script runs all neccesary objetcs to transfer files. The test script requires three arguments: actio, filename, and number of client. For the test script to properly work all three arguments must be present.

How to run the test script

./testTCP.sh <action> <filename> <number of client>

Example

./testTCP.sh put declaration.txt 1 State Diagram

State Diagram

State Diagram

Lab Instructions.

nets-tcp-file-transfer

For this lab, you must define a file transfer protocol and implement a client and server. The server must be

  • single-threaded,
  • and accept multiple concurrent client connections.

Like the demo code provided for this course, your code

  • should be structured around a single loop with a single call to select(),
  • and all information about protocol state should be explicitly stored in variables

Recall that unlike UDP, which is a message-oriented protocol, TCP is stream-oriented.

A practical implication of this difference is that the outputs of multiple writes may be concatenated and reads may only return a portion of the data already sent. You are strongly encouraged to test your implementation using the stammering proxy from https://github.com/robustUTEP/nets-tcp-proxy.git

tcp-protocol's People

Contributors

abgomez avatar robustutep avatar

Watchers

James Cloos 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.