Re: remote netcat talking to a Java app
neuneudr@yahoo.fr wrote:
Hi all,
is it possible to have a Java app listen on a socket (?)
and be *instantly* notified when a remote shell script
netcats something on that socket?
Depends on your definition of instantly but UDP is going to be faster
than making a TCP/IP connection. Will it be really fast? Yes! You
could give some indication of what you think you need in terms of speed.
I have control on the exact number of bytes sent by
netcat. Say the shell script does this:
echo "something" | netcat 10.0.0.39 3423
And I've got a Java app configured to 'listen' on
socket 3423, can I be instantly notified when the
9 letters of "something" have been netcat'ed.
Pretty darn fast.
Imagine, out of simplicity (?) that it's always
exactly the same number of bytes that are going
to be sent by netcat and that netcat shall work
in TCP mode.
OK, then it will be a little slower than UDP but the fixed length record
makes it pretty easy to know when to disconnect.
What should I do on the Java side? Which class
should I use and how can I do so that I don't need
to 'poll' the socket but be instantly notified when
something arrives on the socket? (it has to work
on Java 5).
Typically if you don't have to do a lot of connections, you can have a
thread loop through ServerSocket.accept() and then another thread to
process the connection. If you need an example, post back.
It is maybe a dumb question but I've got no idea
as to how Java application listen on sockets and
how they're supposed to act when something comes
on the socket.
Any explanation greatly appreciated : )
See above.
In terms of raw speed, UDP is going to be much faster since no
connection transaction or confirmation of data arrival is going to have
to take place as with TCP/IP. You could open a DatagramSocket and block
on a read. Then when a packet arrives you can process the data and wait
for the next packet. If the packets are all going to be small messages
or bits of data then I think it will be easier to use UDP but you have
the risk that UDP packets can be lost. That risk is pretty low on a
closed network but if you are sending these messages around the world,
the odd packet might get lost. If 100% packet arrival is not critical
then I would still suggest UDP for speed.
--
Knute Johnson
email s/nospam/knute2009/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access