Mail Archives: cygwin/1998/03/13/14:42:14
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 AT mech DOT uwa DOT edu DOT au /
/ Personal email barneyd AT cyllene DOT uwa DOT edu DOT 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 AT cygnus DOT com" with one line of text: "help".
- Raw text -