For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > June 2005 > Writting a UDP server program under inetd/xinetd









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Writting a UDP server program under inetd/xinetd
shallyee@yahoo.co.jp

2005-06-06, 3:58 pm

I know a tcp server program under xinetd communicates with clients by
just reading/writeing stdin/stdout. This greatly simplify debugging the
program.

Now, I am writting a UDP server under xinetd. Client can send it's
message to server, but server cannot send response by simply printf the
message to stdout. I guess, this is because unlike the TCP, these is no
session information, and xinetd does not know where to connect server's
stdout to.

I read the manual of xinetd, and tried many googles buf found nothing
help. Can anybody over there explain how to do this, or tells "it's
impossible!!" if he is sure.

Thanks.

David Schwartz

2005-06-07, 3:57 am


<shallyee@yahoo.co.jp> wrote in message
news:1118056708.854990.89720@g43g2000cwa.googlegroups.com...

>I know a tcp server program under xinetd communicates with clients by
> just reading/writeing stdin/stdout. This greatly simplify debugging the
> program.


> Now, I am writting a UDP server under xinetd. Client can send it's
> message to server, but server cannot send response by simply printf the
> message to stdout. I guess, this is because unlike the TCP, these is no
> session information, and xinetd does not know where to connect server's
> stdout to.


Sure you can, the socket is a connected UDP socket. (Google for
information if you don't know what this is.) But you still should not use
'printf' because it doesn't give you appropriate control. Use 'write' or
'send'.

DS


Casper H.S. Dik

2005-06-07, 8:58 am

"David Schwartz" <davids@webmaster.com> writes:


><shallyee@yahoo.co.jp> wrote in message
>news:1118056708.854990.89720@g43g2000cwa.googlegroups.com...


[color=darkred]
[color=darkred]
> Sure you can, the socket is a connected UDP socket. (Google for
>information if you don't know what this is.) But you still should not use
>'printf' because it doesn't give you appropriate control. Use 'write' or
>'send'.


It's not a connected UDP socket; inetd hands of the unconnected socket
to the child for handling the current pending and all further
incoming messages for a period of time.

The child MUST use recvfrom and sendto if it wishes to send an
answer.

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
David Schwartz

2005-06-07, 4:02 pm


"Casper H.S. Dik" <Casper.Dik@Sun.COM> wrote in message
news:42a56469$0$49265$e4fe514c@news.xs4all.nl...

> It's not a connected UDP socket; inetd hands of the unconnected socket
> to the child for handling the current pending and all further
> incoming messages for a period of time.
>
> The child MUST use recvfrom and sendto if it wishes to send an
> answer.


Really?! Even if "wait" is false? I guess I'm getting old.

DS


shallyee@yahoo.co.jp

2005-06-09, 3:58 pm

Following is my UDP server program under xinetd.
How to pass first parameter of send/sendto (the socket descriptor)?

int main()
{
char buf[100];
gets(buf); //in packet sent from client dumped here, and received
to "buf"
puts(buf);
fflush(stdout); //no out packet dumped here
return 0;
}

Rainer Temme

2005-06-09, 3:58 pm

shallyee@yahoo.co.jp wrote:
> Following is my UDP server program under xinetd.
> How to pass first parameter of send/sendto (the socket descriptor)?
>
> int main()
> {
> char buf[100];
> gets(buf); //in packet sent from client dumped here, and received
> to "buf"
> puts(buf);
> fflush(stdout); //no out packet dumped here
> return 0;
> }
>


Hi shallyee,

to my knowledge, this is not how inetd is working with
udp-servers ...

Rather than inheriting the new connection (like with tcp) to
stdin/out/err of the forked server-process,
inetd connects stdin/out/err of the forked
process to the udp-socket...remember: udp is connection_less_

Therefore you cannot do read()/write() ... you'll
have to use recvfrom() / sendto() ... both of them
have additional arguments fro the required addressing.

Regards ... Rainer

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com