From: barneyd@cyllene.uwa.edu.au (Barney Dalton)
Subject: Re: Fw: Please review my Sockets() code, anyone?
13 Mar 1998 14:42:14 -0800
Message-ID: <Pine.OSF.3.95.980312102118.13825D-100000.cygnus.gnu-win32@cyllene.uwa.edu.au>
References: <00a901bd4c36$93d50c80$299f23cb@markread>
Reply-To: barney@mech.uwa.edu.au
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
To: Mark Read <mread@ozemail.com.au>
Cc: gnu-win32@cygnus.com, haeb@demon.net


on the serve side you need to use the 'ns' socket handle returned by
accept not the original 's' handle. 's' is till listening for other
clients, while 'ns' is a handle to client that just connected.

barney

On Tue, 10 Mar 1998, Mark Read wrote:

> >  // accept a connection if one in the queue
> >  len = sizeof(struct sockaddr_in);
> >  printf("\n  calling accept()...");
> >  if ((ns = accept(s, (struct sockaddr *) &address, &len)) < 0)
> >  {
> >   printf("failed");
> >   break;
> >      }
> >  else
> >  {
> >   printf("ok");
> >  }
> >
> >  n = recv(s, buf, MAXBUFSIZE, 0);
> >         // **********************************************
> >  // this works (doesn't crash system)
> >  // but nothing is rcvd (well, nothing is printed)
> >  while((n = recv(s, buf, MAXBUFSIZE, 0)) > 0)
> >  {
> >   //write(1, buf, n);
> >   printf("\n  s=%d", s);
> >   printf("\n  n=%d", n);
> >   printf("\n  buf=[%s]", buf);
> >   //printf("%d bytes rcvd", n);
> >  }
> >         // **********************************************
> >
> >
> >
> >  //printf("\n-----------------");
> >
> >  // send a reply
> >  printf("\n\n  sending stuff to caller...");
> >  n = send(s, "hello", 5, 0);
> >  printf("\n  n = %d", n);
> >
> >  printf("\n  closing call...");
> >  close(ns);
> >
> >  //printf("\n  sleeping...");
> >  //sleep(1000);
> >  //printf("back from sleeping !!");
> >  if (bEnd == 1) break;
> >  printf("\n\nlistening for a caller on port %d (press 'ctrl-c' to
> >quit)...", PORTNO);
> >}
> >
> >printf("\nclosing socket...");
> >close(s);
> >  exit(0);
> >}
> >
> >
> >// =====================================================
> >// If an op sys signal is rcvd (like ctrl-c) then abort.
> >// =====================================================
> >void handler(int sig)
> >{
> >bEnd = 1;
> >}
> >
> >

/**********************************************************/
/ Barney Dalton                                            /
/ Computer support  support@mech.uwa.edu.au                /
/ Personal email    barneyd@cyllene.uwa.edu.au             /
/ Work Phone        (61) (8) 93803058 or 93803051          /            
/ Twist my arm :    http://telerobot.mech.uwa.edu.au       /
/**********************************************************/

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".
