• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4322
  • Last Modified:

PEER TO PEER FILE SHARING Example in C

I need help with the basic code for a file sharing protocol in C . I have a file with details and some of the protocol to use. I need a good starting point, maybe an example code for the peer to peer file sharing. I have to use gcc to compile and test the code.
This is the basic code that I am starting with:
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

int main(int argc, char *argv[])
{
    int sockfd, portno, n;
    struct sockaddr_in serv_addr;
    struct hostent *server;

    char buffer[256];
    if (argc < 3) {
       fprintf(stderr,"usage %s hostname port\n", argv[0]);
       exit(0);
    }
    portno = atoi(argv[2]);
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if (sockfd < 0)
        error("ERROR opening socket");
    server = gethostbyname(argv[1]);
    if (server == NULL) {
        fprintf(stderr,"ERROR, no such host\n");
        exit(0);
    }
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = AF_INET;
    bcopy((char *)server->h_addr,
         (char *)&serv_addr.sin_addr.s_addr,
         server->h_length);
    serv_addr.sin_port = htons(portno);
    if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
        error("ERROR connecting");
    Any advice on what to do next for file uploading. I really need some sample coding. Please view the protocol.doc for details
PIC2005422557394586.JPG
Protocol.doc
0
Jgreer2011
Asked:
Jgreer2011
  • 6
  • 4
2 Solutions
 
ssnkumarCommented:
Give me some time. I will read the attached doc tonight and see if I can suggest something.
0
 
Jgreer2011Author Commented:
Ok Thanks
0
 
Jgreer2011Author Commented:
Do you have any suggestions on where I should start? Or resources to check out to give me a example?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
ssnkumarCommented:
You had opened another question on the same subject, right?
So, I thought, you already got some answers there.

Here is an explanation from HowStuffWorks: http://computer.howstuffworks.com/bittorrent1.htm

P2P also uses socket programming for network communication.
But, more than programming, it is the architecture that is important here.
So, you will have to first understand the subject, write algorithms and then only attempt to write code.
0
 
Jgreer2011Author Commented:
What are the steps for implementing a peer to peer file sharing protocol?

What does the protocol contain.? A basic model for the development;
Such as order of connection() function, bind(), connect() etc... or generic
pseudo code??
0
 
ssnkumarCommented:
> Such as order of connection() function, bind(), connect() etc
This order is same for any network programming.
But, P2P is not just network programming.
And there are so many of them and each of them have different architectures.
And hence, each of them have different code.
Everything depends on what is your goal?
So, I think, you should first understand the concept well and then write an algorithm.
Without this, directly writing pseudocode will not take you anywhere.

Here is a tutorial which talks about the concept of P2P and also gives an architecture:
http://www.codeproject.com/KB/vbscript/Generic_P2P_Architecture.aspx

Here is a link, which talks about open source implementations:
http://www.junauza.com/2008/01/freeopen-source-p2p-file-sharing.html

Here is an implementation from gogle: http://code.google.com/p/tarts/
0
 
Jgreer2011Author Commented:
OK thanks
0
 
Jgreer2011Author Commented:
Can you view the protocol.doc under the screen view above for more details of what I am working on
0
 
Jgreer2011Author Commented:
Ok I just completed it. The peer is a combination of a client and server, so the program has a void client and server functions that are called based on the request from the other peers.  It was complicated but simple after you plan the functionality of the program.
0
 
ssnkumarCommented:
> It was complicated but simple after you plan the functionality of the program.
Good.
0
 
evilrixSenior Software Engineer (Avast)Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now