slow down by socket

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();
                        }
                  }
turbot_yuAsked:
Who is Participating?
 
havman56Connect With a Mentor Commented:

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
 
itsmeandnobodyelseConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.