0

I am trying to talk to a machine that is connected to my local machine, using ssh, socat, and another utility I made.

On source machine I am doing:

ssh root@localhost -p 2004 'socat -u TCP-LISTEN:5000 OPEN:foo.test,creat'

(The 4000 maps to the 5000 using my utility that is currently running, not relevant to problem) then doing:

socat -d -d TCP:localhost:4000 ./some_file

And the file transfer occurs correctly, the problem is that I need to be doing these kinds of operations in quick succession and the initial socat TCP-LISTEN server setup does not exit cleanly I guess because I need to wait until the port cleans up, otherwise I get errors of:

2016/05/14 11:56:01 socat[655] E bind(3, {LEN=0 AF=2 0.0.0.0:5000}, 16): Address already in use

Is there a socat option I'm missing that cleans up cleanly on any kind of exit? I basically need this for a file transfer, I only need the socat on the remote machine to go off once.

EDIT: I'm purposefully having to use ssh because the file path for OPEN is different each time and this will have to be done quickly, one after another.

1

You can change the TCP-LISTEN:5000 to TCP-LISTEN:5000,reuseaddr but the problem may simply be that, for example, during testing you are interrupting the ssh with Control-C and this is not stopping the socat on the remote.

Note that you can avoid having to repeatedly launch socat to do the same thing over again by simply asking it to fork and listen for a new connection again:

socat -u TCP-LISTEN:5000,reuseaddr,fork OPEN:foo.test,creat
  • I should have been clear, it needs to be a one time creation because the file path is different each time – Edgar Aroutiounian May 14 '16 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.