performance/tcpsclientthroughput.c
///////////////////////////////////////////////////////////////////////////////
// Filename: tcpsclientthroughput.c
///////////////////////////////////////////////////////////////////////////////
// Purpose: measures performance of a TCP connection (socket version)
// uses tcpserverconcurrent(.c) as TCP server
///////////////////////////////////////////////////////////////////////////////
// History:
// ========
//
// Date Time Name Description
// -------- -------- -------- ------------------------------------------------
// 96/03/01 17:00:19 muellerg: created
//
///////////////////////////////////////////////////////////////////////////////
// Feature test switches ///////////////////////////// Feature test switches //
/* NONE */
// System headers /////////////////////////////////////////// System headers //
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#ifndef sun
#include <strings.h>
#endif
#include <unistd.h>
// Local headers ///////////////////////////////////////////// Local headers //
#include "../common.h"
// Macros /////////////////////////////////////////////////////////// Macros //
/* NONE */
// File scope objects /////////////////////////////////// File scope objects //
/* NONE */
// External variables, functions, and classes ///////////// External objects //
/* NONE */
// Signal catching functions ///////////////////// Signal catching functions //
/* NONE */
// Structures, unions, and class definitions /////////////////// Definitions //
/* NONE */
// Functions and class implementation /// Functions and class implementation //
/* NONE */
// Main /////////////////////////////////////////////////////////////// Main //
/*
* Example of client using the TCP protocol.
*
* paramteters:
*
* argv[1]: server internet address (in dot-form)
* argv[2]: port number of server
*/
int
main(int argc, char *argv[])
{
error.set_program_name(argv[0]);
if(argc!=3)
{
cerr << "Usage: " << argv[0] << " serveraddr port" << endl;
exit(EXIT_FAILURE);
}
int sockfd;
struct sockaddr_in serv_addr;
int portnumber = -1;
// get port number
portnumber = atoi(argv[2]);
if(portnumber <1)
{
cerr << "illegal port number" << endl;
exit(EXIT_FAILURE);
}
// Fill in the structure "serv_addr" with the address of the
// server that we want to connect with.
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr(argv[1]); // addr of host
serv_addr.sin_port = htons(portnumber);
// create a TCP socket (an Internet stream socket).
if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
error.system("client: can't create stream socket");
// connect to the server
if (connect(sockfd, (struct sockaddr *) &serv_addr,
sizeof(serv_addr)) < 0)
error.system("client: can't connect to server");
writedata(argv[0], "write", sockfd);
close(sockfd);
return(EXIT_SUCCESS);
}