![]() |
| | #1 |
| Registered User Join Date: Oct 2003
Posts: 94
| Basically this hacked up version of a tcp/ip tutorial is supposed to make as many connections as possible, then report how many it was able to make. This will tell you how many active TCP connections can exist. But it doesn't work. Basically when I run it agaisnt linux or solaris boxes, I get 188 as the result, and it just sits their afterwards. Now, I know that the number should be a lot higher than 188, and also that the numbers are different for solaris and linux. Here's the code: Code: #include <stdio.h> /* for printf() and fprintf() */
#include <sys/socket.h> /* for socket(), connect(), send(), and recv() */
#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
#include <stdlib.h> /* for atoi() and exit() */
#include <string.h> /* for memset() */
#include <unistd.h> /* for close() */
#define MAXCONN 1024 /* Max number of connections */
int main(int argc, char *argv[])
{
int sock[MAXCONN]; /* Socket descriptor */
struct sockaddr_in echoServAddr; /* Echo server address */
unsigned short echoServPort; /* Echo server port */
char *servIP; /* Server IP address (dotted quad) */
char *echoString; /* String to send to echo server */
int i=0,s=0,numconn;
if (argc < 2) /* Test for correct number of arguments */
{
fprintf(stderr, "Usage: %s <IP> <Port>\n",
argv[0]);
exit(1);
}
servIP = argv[1]; /* First arg: server IP address (dotted quad) */
echoServPort = atoi(argv[2]); /* Use given port, if any */
/* Create a reliable, stream socket using TCP */
printf("Creating %d sockets for the test...",MAXCONN);
i=0;
while (i<MAXCONN) {
if ((sock[i] = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
s=1;
i++;
}
printf("Done.\n");
printf("Currently opening connection number:\n");
/* Construct the server address structure */
memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Zero out structure */
echoServAddr.sin_family = AF_INET; /* Internet address family */
echoServAddr.sin_addr.s_addr = inet_addr(servIP); /* Server IP address */
echoServAddr.sin_port = htons(echoServPort); /* Server port */
/* Establish the connection to the echo server */
s=0;
i=0;
while (s!=1) {
if (connect(sock[i], (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0)
s=1;
printf("\b\b\b%d",i);
i++;
if (i>MAXCONN) {
printf("\nReached max number of connections. Recompile? ;-)\n");
s=1;
}
sleep(0.2);
}
close(sock[0]); //havent gotten around to closing them all, but i will
exit(0);
}
__________________ -Jack C jack {at} crepinc.com http://www.crepinc.com Last edited by crepincdotcom; 08-04-2004 at 12:19 PM. Reason: Fixed formatting |
| crepincdotcom is offline | |
| | #2 |
| Registered User Join Date: Nov 2001
Posts: 1,348
| Do you mean that the program has different results depending on the platform it connects to? Kuphryn |
| kuphryn is offline | |
| | #3 |
| Registered User Join Date: Oct 2003
Posts: 94
| No, what I mean is that i SHOULD be different for different OS's. It's always in the thousands. Problem is, like I said, it hangs at 188 connections. Which isn't right. Did you happen to run the code, and get the same thing? thanks
__________________ -Jack C jack {at} crepinc.com http://www.crepinc.com |
| crepincdotcom is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Strange string behavior | jcafaro10 | C Programming | 2 | 04-07-2009 07:38 PM |
| Help with FIFO QUEUE | jackfraust | C++ Programming | 23 | 04-03-2009 08:17 AM |
| HELP!!!!emergency Problem~expert please help | unknowppl | C++ Programming | 9 | 08-21-2008 06:41 PM |
| help with queues | Unregistered | C Programming | 3 | 05-21-2002 09:09 PM |
| help with queues | Unregistered | C Programming | 3 | 05-21-2002 11:39 AM |