Using C + + to develop the file upload function based on TCP protocol

Source: Internet
Author: User

Using C + + to develop the file upload function based on TCP protocol

2005 I am working as a programmer in a game company, I have been watching the book "Windows network Programming", I have tried every IO model mentioned in it, it is highly recommended that students who learn network programming read more deeply than Apue.

    • This is part of a bank AD project (a peer video)
    • The IO model uses the blocking mode, which is uploaded directly when the file is opened.
    • Compile with VC 2003, generate Win32 DLL
    • Perfectly formed, Csimplesocket,creadstream
    • DLL output a virtual class

      1. extern "C" __declspec(dllexport)
      2. Isendfileinterface * createsendfile()
      3. {
      4. return new cfileclient();
      5. }
    • The interface is defined as follows

      1. typedef struct
      2. {
      3. unsigned int uploaded; //Number of bytes already uploaded
      4. bool finished;
      5. }transinfo, *ptransinfo;
      6. struct isendfileinterface
      7. {
      8. Virtual ~isendfileinterface() {};
      9. //return>0:file Size
      10. //return=0:zero byte file or error
      11. Virtual unsigned int chosefile(const char *file ,int type) =0;
      12. Connecting to a server
      13. Virtual bool Connect(const char *host,unsigned short port) =0;
      14. Blocking calls
      15. -1:socket Error
      16. 0: Upload Complete
      17. Virtual int SendFile(ptransinfo info) =0;
      18. Virtual void Stop() =0;
      19. Virtual const char *geterror() =0;
      20. };

Developing TCP protocol-based file upload functionality in C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.