Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* [Q] Strange behavior with sockets, please help.
@ 1995-09-07  4:00 Herve Soulard
  0 siblings, 0 replies; only message in thread
From: Herve Soulard @ 1995-09-07  4:00 UTC (permalink / raw)


Hello,

I have a strange behavior with socket (TCP) use on OSF1 on alpha,
DEC OSF/1 V3.0 (Rev. 347).

Basically, the two programs (osock & isock) included below act as
a client and a server, respectively, connected by a TCP socket; they
do the following:


	Host 1				Host 2

	osock                		isock
	-----				-----

	get time1			wait for a
					message
	send N messages
	of X bytes      --------------> receive message
	& wait for an  
	return		
					send back a message
	receive msg	<-------------- of 16 bytes

	get time2

 	display  time2-time1


The result of this simple sequence is a time that varies
widely.

For example, sending 60 messages of 10240 bytes gives me:

	try 1 =   37 ms
	try 2 = 1107 ms
	try 3 =  610 ms
	try 4 =   28 ms

I cannot explain this. If somebody has an answer to this
problem....

Note that it depends of the size of the message and of the
number of messages sent. It works fine on SunOS

		Herve Soulard.

----------------------------------------------------------------
/*
   osock.c : the client part.

   Send 'loop' messages of 'len' bytes, then wait for a 
   message of 16 bytes.

   Usage:  osock host port loop len
*/

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/time.h>

char buffer[1000000];

main (int argc, char **argv)
{
    struct sockaddr_in dest;
    struct hostent *host;
    struct in_addr ina;

    int    i, j, w;

    struct timeval  start;
    struct timeval  end;
    unsigned long diff;

    int    fd, loop, len;

    host = gethostbyname(argv[1]);
    
    fd = socket(AF_INET,SOCK_STREAM,0);

    dest.sin_family = AF_INET;
    bcopy(host->h_addr, &dest.sin_addr, host->h_length);
    dest.sin_port = atoi(argv[2]);

    connect(fd, &dest, sizeof dest);

    loop = atoi(argv[3]);
    len  = atoi(argv[4]);

    gettimeofday(&start, (struct timezone *)0);

    for (w = 0; w < loop; w++) {
        j = send(fd, buffer, len, 0);
        i = 0;
        do {
            j = recv(fd, buffer, 16, 0);
            i += j;
        } while (i < 16);
    }
    
    gettimeofday(&end, (struct timezone *)0);

    diff = (end.tv_sec  - start.tv_sec)*100 +
           (end.tv_usec - start.tv_usec)/10000;

    printf("\nTime = %9lu ms \n", diff);

    close(fd);
}
----------------------------------------------------------------
----------------------------------------------------------------
/*
   isock.c : the server part.

   Wait for a message of 'len' bytes, then return a 
   message of 16 bytes.

   Usage:  isock port len
*/

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

char buffer[1000000];

void readMsg(int fd, int len)
{
    int  i, j;
    
    for (;;) {
        i = 0;
        do {
            j = recv(fd, buffer, len, 0);
            if (j == 0) {
                close (fd);
                return ;
            }
            i += j;
        }
        while (i < len);
        j = send(fd, buffer, 16, 0);
    }
}


main (int argc, char **argv)
{
    int s, l, fd;
    struct sockaddr_in dest,source;

    s = socket(AF_INET,SOCK_STREAM,0);

    dest.sin_family = AF_INET;
    dest.sin_addr.s_addr = INADDR_ANY;
    dest.sin_port = atoi(argv[1]);

    bind(s, &dest, sizeof dest);

    getsockname(s, &dest, &l);

    listen(s, 10);

    do {
	l = sizeof source;
        fd = accept(s, &source, &l);
        readMsg(fd, atoi(argv[3]));
    } while (1);
}
----------------------------------------------------------------





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1995-09-07  4:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-09-07  4:00 [Q] Strange behavior with sockets, please help Herve Soulard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox