Guys I know I'm noob xD
But i'll show you what i did with few tutorials.
And its creating the file but its not write its right ..
I tried to send a .txt file with some text in it ..
and its create the file, without the text in it..
here the functions:
void FileRecive(char *Filename)
{
FILE *File = fopen(Filename, "wb");
char Size[128];
recvfrom(Socket, Size, 128, 0, (sockaddr*)&Addr, &Addrlen);
Size[127] = '\0';
int IntSize = atoi(Size);
while(IntSize > 0)
{
char Buffer[1500];
if(IntSize >= 1024)
{
recvfrom(Socket, Buffer, 1024, 0, (sockaddr*)&Addr, &Addrlen);
fwrite(Buffer, 1024, 1, File);
}
else
{
recvfrom(Socket, Buffer, IntSize, 0, (sockaddr*)&Addr, &Addrlen);
Buffer[IntSize] = '\0';
fwrite(Buffer, 1024, 1, File);
}
IntSize -= 1024;
}
fclose(File);
}
void SendFile()
{
std::ifstream File;
File.open("C:\\Text.txt", std::ios::in| std::ios::binary| std::ios::ate);
int Size = (int)File.tellg();
File.close();
char FileSize[10];
itoa(Size, FileSize, 10);
sendto(Socket, FileSize, strlen(FileSize), 0, (sockaddr*)&Addr, sizeof(Addr));
FILE *MyFile = fopen("C:\\Text.txt", "rb");
while(Size > 0)
{
char Buffer[1500];
if(Size >= 1024)
{
fread(Buffer, 1024, 1, MyFile);
sendto(Socket, Buffer, 1024, 0, (sockaddr*)&Addr, sizeof(Addr));
}
else
{
fread(Buffer, 1024, 1, MyFile);
Buffer[Size] = '\0';
sendto(Socket, Buffer, Size, 0, (sockaddr*)&Addr, sizeof(Addr));
}
Size -= 1024;
}
fclose(MyFile);
}