sendfile(string path)
{
int length;
char buffer[10];
ifstream in(path.c_str() , ios::binary);
in.seekg(0 , ios::end);
length = in.tellg();
in.seekg(0 , ios::beg);
stringstream infofile;
string name = splitname(path);
infofile <<"info" << " " << name << " " << length;
string infoBuffer = infofile.str();
send(infoBuffer);
while(!in.read(buffer , 1).eof())
{
cout <<::send(sock , buffer , 1 , 0);
}
cout << "File sent" << endl;
}
receivefile(string path)
{
char buffer[10];
string recvBuffer;
ofstream in(path.c_str() , ios::binary);
recv(recvBuffer);
if(recvBuffer.compare(0 , 4 , "info") == 0)
{
string name = getFileName(recvBuffer);
string size = getFileSize(recvBuffer);
cout << "File name is: " << name << endl;
cout << "Size of file is: " << size << endl;
}
while(int i = ::recv(sock , buffer , 1 , 0) > 0)
{
cout << i;
in.write(buffer , 1);
}
cout << "File received" << endl;
}
my problem is that it sends and receives the file but only if i stop the program,if not it just remains stuck in the while loop in receive() function ....why is that ?