我有一个简单的xinetd控制脚本,它封装了在给定端口上侦听的简单Java应用程序。在xinetd通过stdin/stdout进行对话时,我想使用netcat将流量重定向到/从java应用程序。目前,我有以下配置。
xinetd
service my_server
{
type = UNLISTED
disable = no
socket_type = stream
protocol = tcp
wait = no
user = root
port = 2177
log_on_success += DURATION HOST USERID
server = /opt/stuff/my_server.sh
}my_server.sh
port=2111
# start the java process on the given port
java -jar /opt/stuff/myserver.jar "$port" &
# redirect traffic using netcat
retry_counter=0
until nc -v 127.0.0.1 ${port}
do
let "retry_counter++"
echo "retrying... (${retry_counter})" >> /var/log/smpp_nc
sleep 0.1
done似乎netcat完成了将数据发送到应用程序的工作,但不是相反的.如有任何帮助/提示,将不胜感激!
发布于 2016-02-21 20:33:16
假设您控制了Java服务器代码,您将添加一层根本不需要的重定向。不要将xinetd配置为调用shell脚本,而是将其配置为调用Java应用程序。然后,只需使用System.in和System.out从Java -它真的很简单!
一旦stdin/stdout连接到xinetd,服务器将能够使用stdin/stdout。
https://stackoverflow.com/questions/29552494
复制相似问题