?
Solved

slow down by socket

Posted on 2005-05-16
2
Medium Priority
?
513 Views
Last Modified: 2012-05-05
Hi Experts,

After I add a simple socket client code to my original program, the original one seems slow down.
The original one is used to upload data from one DB to another.
And the code for socket is just to send several strings.

Have I missing somewhere to make the speed low, originally the upload speed is quite fast.

Thanks and Regards,

Turbot

            
      // Initialize Winsock.
            WSADATA wsaData;
            int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
            if ( iResult != NO_ERROR )
                  printf("Error at WSAStartup()\n");

            // Create a socket.
            SOCKET m_socket;
            m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
      
            if ( m_socket == INVALID_SOCKET ) {
                  printf( "Error at socket(): %ld\n", WSAGetLastError() );
                  WSACleanup();
                  //return;
                  }
            else{
                  // Connect to a server.
                  sockaddr_in clientService;
      
                  clientService.sin_family = AF_INET;
                  clientService.sin_addr.s_addr = inet_addr( IP_ADDRESS_PQHUB );
                  clientService.sin_port = htons( PORT_PQHUB );

                  if ( connect( m_socket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR) {
                        printf( "Failed to connect.\n" );
                        WSACleanup();
                        //return;
                        }
                  else {//connection is successful                        
                        bytesSent = send( m_socket, sendbuf, strlen(sendbuf), 0 );
                        printf( "Bytes Sent: %ld, %s \n", bytesSent, sendbuf );
                        WSACleanup();
                        }
                  }
0
Comment
Question by:turbot_yu
2 Comments
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 1000 total points
ID: 14017126
Actually the code you posted could not be responsible to slow down the program if it runs once. If it runs in a loop, of course it could decrease overall performance, especially if you are calling WSAStartup, socket(), connect(), WSACleanup() any time you are sending. Note, these calls should happen once and only once, best in the constructor of a socket class. Also printf calls as well as debug mode could make as program significantly slower than before, but that wasn't determinable from the code you posted.

Regards, Alex
0
 
LVL 4

Accepted Solution

by:
havman56 earned 1000 total points
ID: 14022920

go to my site i have hosted free code

http://micro_mangal.tripod.com


go to free code webpage where i have full socket program which has both client and server
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question