david
david

Reputation: 21

Writing output from a socket

I have 2 machines A and B.

In machine A, I do

echo "Hello World" > /dev/tcp/{Bs_ip}/12345

In machine B, how do I write a script that runs in the background, listens on port 12345, and prints whatever it receives from port 12345 to stdout?

BTW both machines are running Red Hat Enterprise Linux AS 4.

Thanks

Upvotes: 2

Views: 315

Answers (2)

shodanex
shodanex

Reputation: 15406

You can use netcact (nc) or netcat on steroids, ie socat. I gave a link to the examples section of the man page, so that you can see how powerful socat is.

socat TCP4-LISTEN:12345 - 

Should do what you want

Upvotes: 0

Bart Sas
Bart Sas

Reputation: 1645

You can do that using netcat:

nc -l -p 123456

If you want to be able to handle multiple connections you will have to use a loop.

Upvotes: 2

Related Questions