Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

sqldatasource dal, wwwxxxenden, convert raid5 to raid 10 mdadm, apache force chunked, nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas, linux raid resync after reboot

Links

XODOX
Impressum

#1: EOF and netcat

Posted on 2007-08-27 15:22:32 by Frederic Mayot

Hi,
I'm running a program in background which reads and writes on standard
input/output.
I'm using netcat to send commands and to read the result.

To start my prog:
netcat -l -u localhost -p 5555 | my_program &

To send commands:
echo "my_command" | netcat -u localhost 5555

The problem is since my_program does not close its file descriptor for
output, the "client" netcat never returns. I tried to write special
characters like 0x1a, 0x03, 0x04 to fake an EOF with no success.

Any idea?

Thanks,
Fred

Report this message

#2: Re: EOF and netcat

Posted on 2007-08-27 20:02:42 by Bill Marcum

On Mon, 27 Aug 2007 06:22:32 -0700, Frederic Mayot
<fred@mayot.net> wrote:
>
>
> Hi,
> I'm running a program in background which reads and writes on standard
> input/output.
> I'm using netcat to send commands and to read the result.
>
> To start my prog:
> netcat -l -u localhost -p 5555 | my_program &
>
> To send commands:
> echo "my_command" | netcat -u localhost 5555
>
> The problem is since my_program does not close its file descriptor for
> output, the "client" netcat never returns. I tried to write special
> characters like 0x1a, 0x03, 0x04 to fake an EOF with no success.
>
> Any idea?
>
> Thanks,
> Fred
>
Change my_program so it does close its output, or make the client close
its output:
echo "my_command" | netcat -u localhost 5555 | head -n 1
or
echo "my_command" | netcat -u localhost 5555 &
sleep 5
kill $!

--
Churchill's Commentary on Man:
Man will occasionally stumble over the truth,
but most of the time he will pick himself up and continue on.

Report this message

#3: Re: EOF and netcat

Posted on 2007-08-27 21:19:06 by Frederic Mayot

On Aug 27, 2:02 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:
> On Mon, 27 Aug 2007 06:22:32 -0700, Frederic Mayot
>
> <f...@mayot.net> wrote:
>
> > Hi,
> > I'm running a program in background which reads and writes on standard
> > input/output.
> > I'm using netcat to send commands and to read the result.
>
> > To start my prog:
> > netcat -l -u localhost -p 5555 | my_program &
>
> > To send commands:
> > echo "my_command" | netcat -u localhost 5555
>
> > The problem is since my_program does not close its file descriptor for
> > output, the "client" netcat never returns. I tried to write special
> > characters like 0x1a, 0x03, 0x04 to fake an EOF with no success.
>
> > Any idea?
>
> > Thanks,
> > Fred
>
> Change my_program so it does close its output, or make the client close
> its output:
> echo "my_command" | netcat -u localhost 5555 | head -n 1
> or
> echo "my_command" | netcat -u localhost 5555 &
> sleep 5
> kill $!
>
> --
> Churchill's Commentary on Man:
> Man will occasionally stumble over the truth,
> but most of the time he will pick himself up and continue on.

Thanks for your help but your first solution does not work. I tried
with and without -u option.

Report this message

#4: Re: EOF and netcat

Posted on 2007-08-28 05:41:33 by Barry Margolin

In article <1188220952.431286.71340@22g2000hsm.googlegroups.com>,
Frederic Mayot <fred@mayot.net> wrote:

> Hi,
> I'm running a program in background which reads and writes on standard
> input/output.
> I'm using netcat to send commands and to read the result.
>
> To start my prog:
> netcat -l -u localhost -p 5555 | my_program &
>
> To send commands:
> echo "my_command" | netcat -u localhost 5555
>
> The problem is since my_program does not close its file descriptor for
> output, the "client" netcat never returns. I tried to write special
> characters like 0x1a, 0x03, 0x04 to fake an EOF with no success.

There's no such thing as an EOF character on Unix. EOF occurs when a
stream or file *ends*. In the case of a network socket, you have to
close the descriptor; of, if it's a stream socket, you can call
shutdown(fd, SHUT_WR).

The only exception to this is in the terminal driver, which lets you
fake EOF on input (since the only real "end" to a terminal stream would
be a hangup of the phone line, and this would be really inconvenient).
But this mechanism doesn't map to any other type of device.

Since you're using UDP, the shutdown() mechanism won't work. netcat
waits until the application closes the pipe before it writes anything.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Report this message

#5: Re: EOF and netcat

Posted on 2007-08-28 23:23:59 by William Park

Frederic Mayot <fred@mayot.net> wrote:
> Hi,
> I'm running a program in background which reads and writes on standard
> input/output.
> I'm using netcat to send commands and to read the result.
>
> To start my prog:
> netcat -l -u localhost -p 5555 | my_program &
>
> To send commands:
> echo "my_command" | netcat -u localhost 5555
>
> The problem is since my_program does not close its file descriptor for
> output, the "client" netcat never returns. I tried to write special
> characters like 0x1a, 0x03, 0x04 to fake an EOF with no success.
>
> Any idea?
>
> Thanks,
> Fred

Solution is to shutdown the client as soon as "EOF" is reached on its
input. 'netcat' unfortunately does not have -q option that 'nc' has.
Try -w option. As you may have guessed, there are more than one
"netcat". :-)

--
William Park <opengeometry@yahoo.ca>, Toronto, Canada
BashDiff: Super Bash shell
http://freshmeat.net/projects/bashdiff/

Report this message