简体   繁体   中英

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. 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. How can I connect to the socat process an do some inputs from my test script? 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. 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. 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)?

SHORT: I wanna connect or pipe to the socat process and NOT to the server because the server is already connected to the socat?

I'm using a UNIX system.

Something like this: 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM