1 Replies - 546 Views - Last Post: 26 December 2008 - 05:00 PM Rate Topic: -----

#1 vAlexv  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 12-December 08

is possible to send a file from my computer?

Posted 25 December 2008 - 08:33 PM

I am learning winsock and have successfully learned to make a console app chat program from my computer with another computer. It is possible to send a file from my computer to my other computer?
It is something like this?
That is to sent mesage? i think but can it send files?
char file[] = "myfile.txt"
send(client, file, sizeof(file),0);
Is This A Good Question/Topic? 0
  • +

Replies To: is possible to send a file from my computer?

#2 UG Cyber  Icon User is offline

  • D.I.C Addict

Reputation: 32
  • View blog
  • Posts: 546
  • Joined: 24-July 08

Re: is possible to send a file from my computer?

Posted 26 December 2008 - 05:00 PM

View PostvAlexv, on 25 Dec, 2008 - 07:33 PM, said:

I am learning winsock and have successfully learned to make a console app chat program from my computer with another computer. It is possible to send a file from my computer to my other computer?
It is something like this?
That is to sent mesage? i think but can it send files?
char file[] = "myfile.txt"
send(client, file, sizeof(file),0);



Yes, actually it's pretty simple.
1) Send the file name to the server
2) Open file in ifstream (or whatever you want to use)
3) start streaming the contents of the file as you fill your buffer.

char ch, Buffer[1024] //send 1kb per packet
ifstream fin;
int Index = 0;
fin.open("FileName.txt");
while((ch = fin.get()) != EOF) //Dont continue after End Of File
{
    Buffer[Index] = ch;
    if (Index == 1024)
    {
        send(sock, Buffer, sizeof(Buffer), 0);
    }
    Index ++;
}
send(sock, "I'm Done", sizeof("I'm Done"), 0);



Wrote in browser, but it should work =)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1