this is the code i have for the Client Server Chat with Multi-Threading.. this is the SERVER code.

I have to make it change so that i can be able to DIVIDE A TXT FILE INTO PACKETS, THEN SEND THEM TO DIFFERENT SERVERS.. SO THAT WHEN A CLIENT ACCESSES THEM , THEN ALL THE PACKETS SHOULD COME TO HIM.. ITS JUST LIKE P2P FILE SHARING..BUT THE DIFFERENCT IS THAT THIS IS DISTRIBUTED COMPUTING..

HOPE YOU UNDERSTAND.. I NEED SERIOUS HELP.. YOU CAN ALSO CHANGE THE CODE AND SEND IT TO ME..


ONE MORE QUESTION:

CAN I GET THE CODE OF P2P FILE SHARING.. IN C++.. {It should work so that i can understand what actually happens "}

*****************************************************************


#include <iostream>
#include <conio.h>
#include <winsock2.h>
#include <string>
#include <pthread.h>
#include <stdio.h>
#include <fstream>

int getpeername(int sockfd, struct sockaddr *addr, int *addrlen);


using namespace std;
char* buf=new char[50];
char*Buffer = new char[50];
SOCKET comm_sock;
void* func1(void*) {


while(1>0)
{

recv(comm_sock, Buffer, 50, 0);
cout<<"from client: "<<Buffer;
cout<<"\n";

}


}
void* func2(void*) {

ifstream fin;

fin.open("1.txt");


while(1>0)
{
cout<<"\nServer\n : ";
cin.getline(buf,50);
send(comm_sock, buf, strlen(buf)+1, 0);
cout<<"\n";


}



}



void main(int argc, char *argv[])
{
pthread_attr_t attr;
pthread_attr_init(&attr);

WSADATA wsadat;
WORD rVersion;
rVersion = MAKEWORD(2,0);

if(WSAStartup(rVersion, &wsadat) != NO_ERROR)
{
cout<<"WSA initialization failed.\n";
WSACleanup();
return;
}

//Creating the welcome socket
SOCKET welcome_socket;
welcome_socket = socket(AF_INET, SOCK_STREAM, 0);

if(welcome_socket == INVALID_SOCKET)//same as this
{
cout<<"Socket could not be created.\n";
WSACleanup();
return;
}

string ipaddress;
int portno;
//cout<<"Enter your IP address: ";
ipaddress= "127.0.0.1";
cout<< "IP IS : "<<ipaddress<<endl;


// cin>>ipaddress;
//cout<<"Enter the port no.: ";//// mostly gave port number above 5000 ////
portno=6789;
cout<<"PORT : "<<portno<<endl;

SOCKADDR_IN sockaddress;
sockaddress.sin_addr.s_addr = inet_addr(ipaddress.c_str());// use at is it always
sockaddress.sin_port = htons(portno);
sockaddress.sin_family = AF_INET;

if(bind(welcome_socket, (SOCKADDR*)(&sockaddress),sizeof(sockaddress)) == SOCKET_ERROR)
{
cout<<"Attempt to bind failed.\n";
WSACleanup();
return;
}

//listen for incoming connection requests on the welcome socket
listen(welcome_socket, 1);


//create a socket for communication by accepting any requests on welcome socket
//SOCKET comm_sock;
SOCKADDR_IN clientaddr;
int addresslen = sizeof(clientaddr);
// char*Buffer = new char[13];

while(!kbhit())
{
comm_sock = accept(welcome_socket, (SOCKADDR*) &clientaddr, &addresslen);
if(comm_sock != SOCKET_ERROR)
{
cout<<"Connection established with client at: "
<<(int)clientaddr.sin_addr.S_un.S_un_b.s_b1<<"."
<<(int)clientaddr.sin_addr.S_un.S_un_b.s_b2<<"."
<<(int)clientaddr.sin_addr.S_un.S_un_b.s_b3<<"."
<<(int)clientaddr.sin_addr.S_un.S_un_b.s_b4<<endl;


//send and receive data;
//threads
pthread_t tid1,tid2;
pthread_create(&tid1, &attr, func1, NULL);

pthread_create(&tid2, &attr, func2, NULL);
pthread_join(tid2, NULL);
pthread_join(tid1, NULL);

}

}

WSACleanup();
return;
}


*****************************************************************