Giter Site home page Giter Site logo

csci-320-socketproject2's Introduction

CSCI-320 Mini-Project: TCP File Transfer

Setup and Installation

This mini-project should be forked. Forking the repo will create a copy on your own GitHub repo. Once the repo is forked, you can clone YOUR repo using PyCharm. Submission entails committing and pushing your changes to your repo.

Introduction

This exercise aims to create a simple TCP file transfer system, where a client will send a file to a server, and the server will receive the file and save it to disk. There are no limits on the size of the file.

In this mini-project, you will implement a simple protocol for file transfer over TCP. Because the socket is UDP, the application layer is responsible for ensuring that the file is transferred without error. While this algorithm addresses some of the reliability transfer issues, many problems related to reliable transfer still need to be addressed.

Note: This mini-project is intended to provide practice in socket programming. File transfer should be done over a TCP socket. This will be the subject of the next mini-project.

The algorithms described below implement the following simple protocol.

Figure 1: Simple file transfer protocol.

1. Implementing the Server

The server should:

  1. Create a socket using the socket function and bind it to the (ip, port) pair. (Implemented)
  2. Receive a message from the client using the recv function.
  3. Decompose the message into an 8-byte integer representing file size. The rest of the bytes should be decoded into a string representing the file name. Use get_file_info().
  4. send b'go ahead' message to the client.
  5. Using the filename provided, open the file for writing using the with python statement. NOTE: since you will be transferring a file over localhost to the same directory, it is important that you modify the filename, say by adding a .temp extension, to avoid overwriting the original file. (Implemented)
  6. Inside the with statement,
    1. Receive a chunk of data.
    2. Update the number of bytes received.
    3. Write the data to the file.
    4. Continue to perform steps 7a-c until all bytes have been received.
  7. If an exception occurs, the file should be deleted. (Implemented)
  8. Close the client socket. (Implemented)
  9. Repeat steps 2 - 8. (Implemented)

2. Implementing the Client

The client should:

  1. Obtain the name of the file to transfer from the command line using sys.argv. (Implemented)
  2. Obtain the size of the file in bytes by using the os.path module.(use get_file_size())
  3. Convert the file size to an 8-byte string using big endian.
  4. Create a TCP socket using the socket function. (Implemented)
  5. Connect to the server using the (ip, port) pair.
  6. Send the 8-byte file size concatenated with the encoded filename to the server.
  7. Wait for the server to send b'go ahead' message. If any other message is sent, raise OSError('Bad server response - was not go ahead!')
  8. Open the file for reading in binary mode using the with python statement.
    1. Read a chunk of data from the file.
    2. If the length of the chunk > 0, then send the chunk to the server else go to step 9. No more chunks to read and send.
    3. Repeat steps 8a - 8b
  9. Close the client socket. (Implemented)

3. Testing Your Implementation

You can test your implementation by running the server and client on the same machine. Make sure to run the server first and then the client. NOTE: as mentioned in section 1 above, it is important that you modify the filename, say by adding a .temp extension, to avoid overwriting the original file. This has already been done on the server's with statement. Such a filename change is only necessary when running both server and client on the same machine and using the same working directory. You do not have to modify the filename if you set the run configuration of the server to use a different working directory from that of the client.

4. Submitting This Work

You are required to commit and push your code to your forked repo.

Tips

  • Make sure to handle errors in your code.
  • Pay attention to the TODO tasks and how they are mapped to the algorithm steps above. This will help guide you in implementing the code.
  • Read the Python documentations for the sys, os, and os.path modules along with associated examples. Avoid Googling the answer as this will get you into the habit of reading documentaton.

Good luck and happy coding!

csci-320-socketproject2's People

Contributors

mylesunlimited avatar mrasamny 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.