I am trying out a simple server program in UNIX (HP_UX 11) which prints out
whatever is sent to it, I am able to create a socket ,bind it to a port and
listen on that port.However when a connection is requested the accept function
returns zero as a socket file descriptor,and recv() gives a error saying
"Socket operattion on a non socket descriptor"
Is 0 a valid socket file descritor? If it is why is recv returning a error?
Any help is appriciated
Thanks and regards
Ravi
@ 0 is not a valid file descriptor.
0: standard input
1: standard output
2: standard error
"Ravindran Maravar" <Ravindra...@cwo.com.au> wrote in message
news:3AA9A8FA...@cwo.com.au...
I don't know which manpage you're reading, but 0 is a perfectly
valid file descriptor and so are 1 and 2. They will become available
as soon as stdin, stdout and stderr have been closed.
-Udo.
Ravindran> Hello ,
Ravindran> I am trying out a simple server program in UNIX (HP_UX 11)
Ravindran> which prints out whatever is sent to it, I am able to
Ravindran> create a socket ,bind it to a port and listen on that
Ravindran> port.However when a connection is requested the accept
Ravindran> function returns zero as a socket file descriptor,and
Ravindran> recv() gives a error saying "Socket operattion on a non
Ravindran> socket descriptor"
Ravindran> Is 0 a valid socket file descritor? If it is why is recv
Ravindran> returning a error?
0 is a valid file descriptor, but it usually refers to stdin.
You didn't post your code, but my advanced network snooping devices
have enabled me to spot the error in your sources anyway: you have
some misplaced or missing parentheses around your accept() call.
--
Andrew.
comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
or <URL: http://www.whitefang.com/unix/>
if((newsfd = accept(sockfd,(struct sockaddr*)&cliAddr,&cliLen))< 0)
{
printf("Cannot accpet connection \n");
exit(1);
}
Any suggestions?
Andrew Gierth wrote:
> >>>>> "Ravindran" == Ravindran Maravar <Ravindra...@cwo.com.au> writes:
>
> Ravindran> Hello ,
> Ravindran> I am trying out a simple server program in UNIX (HP_UX 11)
> Ravindran> which prints out whatever is sent to it, I am able to
> Ravindran> create a socket ,bind it to a port and listen on that
> Ravindran> port.However when a connection is requested the accept
> Ravindran> function returns zero as a socket file descriptor,and
> Ravindran> recv() gives a error saying "Socket operattion on a non
> Ravindran> socket descriptor"
>
> Ravindran> Is 0 a valid socket file descritor? If it is why is recv
> Ravindran> returning a error?
>
> 0 is a valid file descriptor, but it usually refers to stdin.
>
> You didn't post your code, but my advanced network snooping devices
> have enabled me to spot the error in your sources anyway: you have
> some misplaced or missing around your accept() call.
Any suggestions?
Does accept() still return 0 if you ensure that FD 0 is in use before
calling accept()? It's a good idea for a daemon to open /dev/null on FD's
0, 1, and 2, just in case some function tries to access stdin, stdout, or
stderr; you don't want that function using the socket when it does this.
If 0 is in use and accept() still returns 0, something is really broken.
--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
I think this could be the solution .I havent tried it out as yet .I will try it out
today and let u guys know abt it......Thanks for the response
Ravi