File Transfer and Communication Within A Network Using Socket Programming
File Transfer and Communication Within A Network Using Socket Programming
End-Semester Report
ON
Submitted By
Minor-I
Abstract:
Sockets play a vital role in client server applications. The client and server can communicate
with each other by writing to or reading from these sockets. One socket (node) listens on a
particular port at an IP, while other socket reaches out to the other to form a connection. In
this project, we have designed software which allows the file transfer across two nodes and
also the communication between them in the form of a chat forum. This will further be
optimized by compressing and decompressing the file at the sender and receiver node
respectively using the Huffman code mechanism.
Introduction:
A socket is the mechanism that most popular operating systems provide to give programs
access to the network. Network program can do lots of work. A simple network Program can
obtain information from many computers located all over the world. It can communicate with
millions of people around the world.
It allows messages to be sent and received between applications (unrelated processes) on
different networked machines. Network programming uses Client-Server model, so network
programming is also Client Server Programming. Where one program starts the
communication called client process or program and other who is waiting for communication
to start called the server process or program. In the simplest case, Client program sends the
request to the server. Server sends the response. Client then obtains the data from the server
and displays it. The Client-Server interaction allows efficient file transfer and also facilitates
real time chatting.
Problem Statement:
Literature Review:
There are various file transfer techniques available in today’s world but all of them possess
some kind of issues and flaws.
● Email: Sending files via email is quite popular but all the major email providers like
Gmail, AOL Mail, and Yahoo!
● Cloud based files sharing: This is certainly the most convenient way to share files of
larger size but in a world full of cybercriminals this is not the most secure option.
● FTP: Data sent via FTP is vulnerable to sniffing, spoofing and brute force attacks,
among other basic attack methods. (Reference :https://digitalguardian.com/blog/what-
ftp-security-securing-ftp-usage).
Objectives Achieved:
Methodology:
▪ One user will act as a server and other as a client. Thus, transfer of files and
communication will take place between the Server and the Client.
▪ Spiral Model will be used to complete the objective of this project. This model has
been chosen for two of its special feature i.e. PROTOTYPE DEVELOPMENT and
RISK ANALYSIS.
Socket Programming:
Client Side:
Create a socket with the socket() system call.
Connect the socket to the address of the server using the connect()
system call.
Send and receive data. There are a number of ways to do this, but
the simplest way is to use the read() and write() system calls.
Server Side:
• Bind the socket to an address using the bind() system call. For a
server socket on the Internet, an address consists of a port number
on the host machine.
• Send and receive data using the read() and write() system calls.
Flowchart for Socket Programming:
Huffman’s Coding Algorithm
Huffman’s algorithm constructs a binary coding tree in a greedy fashion, starting with the
leaves and repeatedly merging the two nodes with the smallest probabilities. A priority queue
is used as the main data structure to store the nodes. The pseudocode appears below.
Algorithm 1: Huffman Coding Input: Array f[1...n] of numerical frequencies or probabilities.
Output: Binary coding tree with n leaves that has minimum expected code length for f.
huffman(f[1...n])
4. i = extractMin(Q)
5. j = extractMin(Q)
9. return T
Sending and Receiving of File:
On Server’s End:
File named ‘output.txt’ is received on server’s end , which was sent from the client.
Communication within the network:
Chat-Forum:
Compression
A file ‘sample1.txt’ is taken to compress. Before compressing its size is 25.6 KB. After this
we run our file compression code.
Now we execute the code on terminal to compress the file named as ‘sample1.txt’.
In the following image we are encoding the file ‘sample1.txt’. After execution of this a new
file named as ‘sample1.txt.zip’ was created.
In this figure we can see the size of the file ‘sample1.txt.zip’ whose size is 16.8KB.
Result:
File Size before Compression: 25.6KB
File Size after Compression: 16.8KB
Decompression
We now take the compressed file ‘sample1.txt.zip’ and perform decompression on it.
A new file named as sample1.txt.zip.txt is formed.
Result
[1]https://pdfs.semanticscholar.org/9ef9/c58042b19d44b428803a5a6c82ecb91b85ca.pdf
[2]https://www.2brightsparks.com/resources/articles/ssh-file-transfer-protocol-explained.pdf
[3] https://gist.github.com/ozcanovunc/e3dda9c0886321fcc6ee
[4]https://stackoverflow.com/questions/18489271/socket-programming-in-cclient-server-
example
[5]http://ijcsit.com/docs/Volume%205/vol5issue03/ijcsit20140503462.pdf
[6]Software Engineering, Pearson Education; Tenth edition by Ian Sommerville
[7]Data Communication and Networking, McGraw Hill Education; Fifth edition by Forouzan
[8]UNIX Network Programming: The Sockets Networking Api, PHI Publications by Bill
Fenner
Approved By