LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-01-2004, 09:24 AM   #1
jhon
Member
 
Registered: Aug 2004
Posts: 32

Rep: Reputation: 15
server side


Hi,

it's the first time I'm writing a server side application under UNIX...

sad event I must say...

if anybody could help me understand why the application doesn't continue after select() even though a client sends msgs that would be great.

THANKS GUYS

Code:

#define SERVER_NAME_LEN 64
#define MSG_LEN 2047


int sock;            /* The socket file descriptor for our "listening"  socket */
int connectlist[5];  /* Array of connected sockets so we know who  we are talking to */
fd_set socks;        /* Socket file descriptors we want to wake up for, using select() */
int highsock;	     /* Highest #'d file descriptor, needed for select() */



int main()
{ 
  int port = 50002;
  struct sockaddr_in server_addr;

  char serverName[SERVER_NAME_LEN];
  struct hostent *hp;

	memset((char *) &server_addr, 0, sizeof(server_addr));
	printf("start\n");

	server_addr.sin_family = AF_INET;// hp->h_addrtype;
	server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
	server_addr.sin_port = htons(port);

	if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) 
	  {
	    perror("socket");
	    exit(-1);
	  }
	printf("sock() = %d\n", sock);

	setnonblocking(sock);
	printf("nonblock()\n");

	if (bind(sock, (struct sockaddr *) &server_addr, sizeof(server_addr)) < 0 )
	  {
		perror("bind");
		close(sock);
		exit(-1);
	  }
	printf("bind()\n");
  
	listen(sock,5);
	printf("listen()\n");

	/* Since we start with only one socket, the listening socket, it is the highest socket so far. */
	highsock = sock;
	printf("highsock = % d\n", highsock);

	memset((char *) &connectlist, 0, sizeof(connectlist));

	while (1)
	  { /* Main server loop - forever */
                            int listnum = 0;
	
	            FD_ZERO(&socks);
	            FD_SET(sock,&socks);
	
	             for (; listnum < 5; listnum++)
	             {
		    if (connectlist[listnum] != 0) 
		          {
			   FD_SET(connectlist[listnum],&socks);
			   if (connectlist[listnum] > highsock)
			   {
				highsock = connectlist[listnum];
			   }
		       	   printf("sock %d in lisetning mode. ", connectlist[listnum]);
			   printf("highsock = % d\n", highsock);
		            }
		printf("connectlist[%d] = 0\n", listnum);
	                }
		printf("built select list()\n");

--------------------->>>>>>>>>>>>>>>>>>>>>>>>

		int readsocks = select(highsock+1, &socks, (fd_set *) 0, (fd_set *) 0, 0);

--------------------->>>>>>>>>>>>>>>>>>>>>>>>
		printf("readsocks = % d\n", readsocks);
		
		if (readsocks < 0)
		  {
			perror("select");
			exit(-1);
		  }
		if (readsocks == 0)
		  {
			/* Nothing ready to read, just show that
			   we're alive */
			printf(".");
			fflush(stdout);
		  } 
		else
		  {
			read_socks();
		  }
	} /* while(1) */
} /* main */

Last edited by jhon; 09-01-2004 at 10:35 AM.
 
Old 09-01-2004, 11:59 AM   #2
jhon
Member
 
Registered: Aug 2004
Posts: 32

Original Poster
Rep: Reputation: 15
maybe the problem is with struct servnet or hostnet?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
server side include syntax help nkoplm Programming 1 11-08-2005 09:53 AM
Hiding Server Side Scripts TomalakBORG Linux - Enterprise 3 07-26-2005 02:47 PM
help with client side NFS-firewall setup and server side NIS-firewall setup niverson Linux - Networking 3 02-02-2004 08:52 AM
Server Side Includes warlock33 Linux - Software 2 02-13-2003 12:58 AM
Server Side Image Animation? Opcode Linux - General 2 06-07-2002 01:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration