LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-24-2020, 06:29 PM   #1
wirelessmc
Member
 
Registered: Aug 2008
Location: San Diego County
Distribution: Slackware
Posts: 183

Rep: Reputation: 37
script to relay an app's stdin/stdout over LAN


I have a need for a shell script that will take the stdin/stdout of an application (executable) and relay it over to (and back from) another local machine on my local network. The application relies on a server client to pipe it's stdin/stdout to/from a graphical interface. So instead of configuring thet GUI with the local executable, I would configure it with the script. The application stdin/stdout is all text based. If you must the interface is called 'Go Text Protocol' or gtp for short. The application will run rather dumbly on a command line/shell with gtp as it's argument:

$ appname gtp

The application has been built on both machines so it could be resident on either one.

The following works remotely with ssh:

$ ssh -t user@remotebox /path/to/appname gtp

No authentication is needed as I have setup ssh-keys on both machines. I am thinking some invocation of netcat [/usr/bin/nc] and ssh should suffice for the script. I just don't know how to construct it. That's why I am posting. Thanks for any ideas on how to create it.
 
Old 09-25-2020, 12:11 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
There should be several ways. One might be along the lines of using standard pipes:

Code:
while sleep 1; do echo whatever; done \
| user@remotebox 'cat | /path/to/appname gtp' \
| /usr/local/bin/localappname
Another might be to make a FIFO pipe (named pipe) on the remote machine using mkfifo and then mounting the remote directory using sshfs. You won't be able to make the named pipe using the mount, but if it is already there, it can still be used via the mount.
 
Old 09-25-2020, 08:41 AM   #3
wirelessmc
Member
 
Registered: Aug 2008
Location: San Diego County
Distribution: Slackware
Posts: 183

Original Poster
Rep: Reputation: 37
Thanks a lot Turbocapitalist. You have the right idea. The two machines will be running the same app (for benchmark purposes) but this will be done through the GUI (client server) as the go between. So the last pipe that addresses the app locally does not seem correct. The approach with mkfifo looks promising but the app needs to be running on the remote machine - not locally. I will look at the doc for mkfifo.
 
Old 09-25-2020, 11:25 AM   #4
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,376

Rep: Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756Reputation: 2756
I like the ssh and nc approach.
Using ssh to tunnel an arbitrary port number 4444 to setup an nc listening process on the remote host,
on the local host, " ssh -L 4444:<remote>:4444 -c 'nc -l -p 4444 | /path/to/appname/gtp' ".
In a second terminal on the local host " /path/to/appname/gtp | nc -p 4444 ".

You might want to add a -w option to the nc listening process to force a timeout.
 
Old 09-25-2020, 11:31 PM   #5
wirelessmc
Member
 
Registered: Aug 2008
Location: San Diego County
Distribution: Slackware
Posts: 183

Original Poster
Rep: Reputation: 37
Thanks allend.

Getting "Unknown cipher type" error when executing the first script for the listening process.

I suspect on your second terminal command you meant the remote machine?

In either case I need this all to be contained in a single script which runs as a self-contained executable on the remote host from the local host.
 
Old 09-26-2020, 12:30 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Quote:
Originally Posted by wirelessmc View Post
The two machines will be running the same app (for benchmark purposes) but this will be done through the GUI (client server) as the go between.
That does not make any sense to me so perhaps I do not understand the task. Can you give more detail about the two instances of the same application which will run on the remote and local systems at the same time? How would they normally communicate when both instances are run on the same machine?
 
Old 09-26-2020, 06:18 PM   #7
wirelessmc
Member
 
Registered: Aug 2008
Location: San Diego County
Distribution: Slackware
Posts: 183

Original Poster
Rep: Reputation: 37
Sure thing TC. My bad for not being clear in the first place...

I need a standalone script that appears to my graphical interface as a single "local" executable. In fact this script will connect to a remote machine (on my LAN) and run said executable on that remote machine. The script I need will pass the text based I/O back and forth from the remote application to the local machine. These executable(s) I am referring to are actually Neural Network based (AI) Go playing engines that I have compiled on my Linux machines. The graphical interface is needed in order to communicate to the Go engines and to actually see the moves on the Go board. If properly scripted the script can run on any number of GUIs. Most these (GUIs) can run as a game editor, connect to a single engine to play against a human (manual play) or pit two go engines against one another. The latter is what I am trying accomplish in order to benchmark the two machines (GPUs) against one another. The executable(s) are compiled either with a CUDA or an OpenCL driver for their back end. They will harness the processing power of your GPU with these drivers. These Go engines which I have now built on two of my machines are very strong. They can defeat very strong Go players including some professionals.

As I had mentioned I can run the application remotely on the local machine from a ssh command as below:

$ ssh -t userlocal@remotemachine /path/to/application/executable gtp

'gtp' above is actually the executable command line argument and can passed as a parameter in the GUI.

The output on the shell is very limited however and the GUI is too dumb to be configured with above command. The GUI's Go engine configuration option has to appear to the GUI as a local executable.


I should have described all this from the beginning but I was trying to avoid being too verbose. Does this help clear up what it is I am trying to do?
 
Old 09-26-2020, 07:08 PM   #8
wirelessmc
Member
 
Registered: Aug 2008
Location: San Diego County
Distribution: Slackware
Posts: 183

Original Poster
Rep: Reputation: 37
I haven't had a chance to look at the mkfifo docs yet but it sounds promising...
 
Old 09-26-2020, 11:04 PM   #9
wirelessmc
Member
 
Registered: Aug 2008
Location: San Diego County
Distribution: Slackware
Posts: 183

Original Poster
Rep: Reputation: 37
This is a good example of using mkinfo with scripts and named pipes. Thank you for telling me about this Turbocapitalist. It looks like I could use this code for what I am trying.
https://www.linuxjournal.com/content...pes-fifos-bash
 
Old 09-27-2020, 09:19 AM   #10
wirelessmc
Member
 
Registered: Aug 2008
Location: San Diego County
Distribution: Slackware
Posts: 183

Original Poster
Rep: Reputation: 37
I just installed 'socat' Slackbuild. This looks very promising when used with named pipes also.
description:
# socat (multipurpose data relay)
#
# socat is a relay for bidirectional data transfer between two
# independent data channels. Each of these data channels may be a file,
# pipe, device (serial line etc. or a pseudo terminal), a socket (UNIX,
# IP4, IP6 - raw, UDP, TCP), an SSL socket, proxy CONNECT connection,
# a file descriptor (stdin etc.), the GNU line editor (readline),
# a program, or a combination of two of these. These modes include
# generation of "listening" sockets, named pipes, and pseudo terminals.
#
# Homepage: http://www.dest-unreach.org/socat
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
using netcat stdout and stdin data between computer and a bash script A-Rap Linux - General 1 03-19-2012 07:53 AM
C++ - Problems while taking over STDIN and STDOUT of child process! MaxistXXL Programming 1 09-30-2010 07:47 PM
Shell script stdout, stderr and stdin solo9300 Linux - General 6 12-29-2009 12:33 AM
How can I handover Stdin/Stdout Operations over TCP to a client initiated program? humandynamo Linux - Software 2 01-27-2009 01:57 PM
stdin -> port -> stdout acid_kewpie Linux - Networking 5 04-12-2002 06:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 09:21 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration