简体   繁体   English

通过管道运行socat进程,但是如何完成呢?

[英]Piping to running socat process, But how is this done?

I have a little problem I have the following situation. 我有一个小问题,我有以下情况。

I programmed a server tool that already works. 我编程了一个已经可以使用的服务器工具。 No I tried to test it with perl. 不,我尝试用perl对其进行测试。 Therefore I wrote an startscript which is just for starting all my processes which I need for testing, and seperate test script. 因此,我编写了一个开始脚本,该脚本仅用于启动测试所需的所有过程以及单独的测试脚本。 The problem is the following: I have to start my SOCAT prog before my server is started in the start script. 问题如下:在启动脚本中启动服务器之前,我必须先启动SOCAT编。 How can I connect to the socat process an do some inputs from my test script? 如何连接到socat进程,并从测试脚本中输入一些信息? Would this be possible? 这可能吗?

OK sorry for the confusing description I try it again: I have two files: One which starts my processes on my server and the socat process for writing data to my server process. 抱歉,我再次尝试进行混乱的描述:我有两个文件:一个用于启动服务器上的进程,另一个用于将数据写入服务器进程的socat进程。 I start also other necessary processes here but they are not important for this problem. 我也从这里开始其他必要的过程,但是它们对于这个问题并不重要。 The second file should just write something to the socat process for sending it to the server. 第二个文件应该只是将一些内容写入socat进程,以将其发送到服务器。 How can I connect to the running socat process (The process has to be started before my server process was started. The reason is that the server can connect to the socat)? 如何连接到正在运行的socat进程(必须在启动服务器进程之前启动该进程。原因是服务器可以连接到socat)?

SHORT: I wanna connect or pipe to the socat process and NOT to the server because the server is already connected to the socat? 简短说明:我想连接或通过管道连接到socat进程而不是服务器,因为服务器已经连接到socat吗?

I'm using a UNIX system. 我正在使用UNIX系统。

Something like this: http://www.thegeekstuff.com/2010/07/perl-tcp-udp-socket-programming/ 像这样的东西: http : //www.thegeekstuff.com/2010/07/perl-tcp-udp-socket-programming/

#!/usr/bin/perl
#tcpclient.pl

use IO::Socket::INET;

# flush after every write
$| = 1;

my ($socket,$client_socket);

# creating object interface of IO::Socket::INET modules which internally creates
# socket, binds and connects to the TCP server running on the specific port.
$socket = new IO::Socket::INET (
PeerHost => '127.0.0.1',
PeerPort => '5000',
Proto => 'tcp',
) or die "ERROR in Socket Creation : $!\n";

print "TCP Connection Success.\n";

# read the socket data sent by server.
$data = <$socket>;
# we can also read from socket through recv()  in IO::Socket::INET
# $socket->recv($data,1024);
print "Received from Server : $data\n";

# write on the socket to server.
$data = "DATA from Client";
print $socket "$data\n";
# we can also send the data through IO::Socket::INET module,
# $socket->send($data);

sleep (10);
$socket->close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在perl脚本完成后触发一个进程并使它继续运行 - Fire a process off and have it keep running after perl script is done 如何将日志的尾部管道传输到脚本导致生成日志的进程停止生成条目? - How can piping tail of a log to a script cause the process generating the log to stop generating entries? 如何调试正在运行的Perl进程? - How to debug a running perl process? 当运行过程不是子进程时,如何在perl中等待运行过程完成? - How to wait for running process to complete in perl when running process is not child process? 如何在Linux中创建运行中的流程图 - How to create a running process graph in Linux 如何在Catalyst App中管理长时间运行的进程? - How to manage a long running process in a Catalyst App? 如何确定Java进程是否在Perl中运行 - How to determine if Java process is running in Perl 使用 Perl CGI 完成 perl 进程后如何使等待消息消失 - How to make the waiting message go away when the perl process is done using Perl CGI 如何检查Unix进程是否在Perl中运行? - How can I check if a Unix process is running in Perl? 如何以编程方式在启动它的同一脚本中终止正在运行的进程? - How can I programmatically terminate a running process in the same script that started it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM