The data download Tool Based on g_soap has a transmission speed of only kb and needs to be improved.

Source: Internet
Author: User
Tags sendfile

Server:

// Struct class ns_downinfo {char m_pbuffer [1024]; int m_nreadsize; bool m_beof;}; struct ns_getdowninforesponse {ns_downinfo return _;}; int NS _ downfile (char * pcfilename, int nposition, struct ns_getdowninforesponse & R); int NS _ gethelloworld (char * & gethelloworldreturn); // register // server. h/******************************** Author: duanyueming creat: creat: Purpose: File Sending module ******************** * **********/# Include "fileinfo. H "# include" ns. nsmap "// # include <fstream> // class server // {// public: // server: Server (INT _ Port = 5678 ); //~ Server (); // int NS _ sendfile (struct soap *, char * filename, int position, struct ns_getfileinfo & S ); /// * char * getfilename (char * _ filepath); * // void initsoap (); // Private: // int m_totalsize; // char * m_filename; // bool m_state; // int m_port; // int m_updatasize; // struct NS _ sendfile * m_sendfile; // struct soap m_soap; //}; // server. CPP // # include "server. H "// Using STD: ifstream; // server: Server (INT _ port )// {// M_totalsize = 0; // m_filename = NULL; // m_state = false; // m_port = _ port; // m_updatasize = 0; ///} // char * server: getfilename (char * _ filepath) // {// m_filename = _ filepath; //// * return _ filepath; * //} // void server: initsoap () // {// soap_init (& m_soap); // socket _ state = soap_bind (& m_soap, null, m_port, 100); // If (_ state = invalid_socket) // {// printf ("the socket BIND error! "); // Exit (1); //} // printf (" socket successful "); // (;;) // {// int _ accept_state = (INT) soap_accept (& m_soap); // If (_ accept_state <0) // {// soap_print_fault (& m_soap, stderr ); // exit (-1); /// printf ("Connect successful"); // soap_serve (& m_soap); // soap_end (& m_soap ); //} // INT server: NS _ sendfile (struct soap *, char * filename, int position, struct ns_getfileinfo & S) // {// ifstream _ fi Le; // _ file. open (filename, STD: IOS: In | STD: IOS: Binary); // If (_ file. is_open () // {// _ file. seekg (position); // m_totalsize = _ file. tellg (); // while (! _ File. EOF () // {// _ file. read (S. m_fileinfo.m_filebuff, 1024); // m_updatasize + = _ file. gcount (); // printf ("sending % 02d %", (m_UpdataSize-m_TotalSize) * 100); // fflush (stdout); // printf ("\ r "); /// //} // _ file. close (); //} // return 0; // inline ns_fileinfo * soap_new_req_ns_fileinfo (struct soap * soap, char m_filebuff [1024], int m_totalsize, bool m_state) // {// ns_fileinfo * _ p = soap_instantiate_ns_fileinfo (soap,-1, null); // If (_ p) // {// _ p-> soap_default (SOAP); // _ p-> ns_fileinfo: m_filebuff = m_filebuff; // _ p-> ns_fileinfo: m_totalsize = m_totalsize; // _ p-> ns_fileinfo: m_state = m_state; //} // return _ p ;//}

  

 

// Client

# Include "soapstub. H "# include" ns. nsmap "# include <fstream> Using STD: ofstream; Using STD: ifstream; int gethelloworld (const char * server) {struct soap str_soap; int nresult = 0; soap_init (& str_soap); char * Buff; // = new char [1024]; soap_call_ns _ gethelloworld (& str_soap, server, "", buff); If (str_soap.error) {soap_print_fault (& str_soap, stderr);} soap_end (& str_soap); soap_done (& str_soap); Return 0;} int downfil E (const char * server) {// read the psourcefilename file from the server and save it as the poldfilename file char * psourcefilename = "D: \ shrike-i386-disc1.iso", * poldfilename = "E: \ 444.txt "; struct soap str_soap; int nresult = 0; soap_init (& str_soap); struct implements Rresponse; soap_call_ns _ downfile (& str_soap, server, "", psourcefilename, 0, Rresponse ); bool beof (false); If (str_soap.error) {soap_print_fault (& str_soap, stderr); beof = True;} ofstream file; If (! Beof) {file. open (poldfilename, STD: IOS: Out | STD: IOS: Binary | STD: IOS: trunc); If (file. is_open () file. write (Rresponse. return _. m_pbuffer, Rresponse. return _. m_nreadsize);} beof = Rresponse. return _. m_beof; int nposition = Rresponse. return _. m_nreadsize; soap_end (& str_soap); soap_done (& str_soap); While (! Beof) {soap_call_ns _ downfile (& str_soap, server, "", psourcefilename, nposition, Rresponse); If (str_soap.error) {soap_print_fault (& str_soap, stderr ); beof = true;} else {If (file. is_open () file. write (Rresponse. return _. m_pbuffer, Rresponse. return _. m_nreadsize); beof = Rresponse. return _. m_beof; nposition + = Rresponse. return _. m_nreadsize;} soap_end (& str_soap); soap_done (& str_soap);} If (file. is_open () file. close (); Return 0;} int main (INT argc, char * argv []) {char * Server = "http: // localhost: 8080"; gethelloworld (server ); downfile (server); Return 0 ;}

The code is incomplete. It is obtained from the broken hard disk... Of course, we can still make an example. I will not introduce it in detail. I believe that anyone who has some programming experience can easily understand it.

The data download Tool Based on g_soap has a transmission speed of only kb and needs to be improved.

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.