xinetd service calls python script (doesn't execute properly)

倾然丶 夕夏残阳落幕 提交于 2019-12-02 06:44:16

The real problem for me is apparently my lack of socket programming knowledge. I found this post online searching for "xinetd python no data" (https://mail.python.org/pipermail/python-list/2007-July/423659.html) which helped me at least get my stuff working and sort of illustrated via example a bit about how socket programming actually works. The solution is below, I removed the raw_input from the original script and replaced it with concepts from the post.

/root/script.py (original)

#! /usr/bin/python
my_name = raw_input("Enter your name: ")
print my_name
quit()

/root/script.py (modified & working)

#! /usr/bin/python
import sys
print "Enter your name:"                
sys.stdout.flush()
my_name = sys.stdin.readline().strip()
print "Your name is %s" % my_name
sys.stdout.flush()
quit()

telnet 192.168.240.37 65123 (actual behavior - working)

[root@netunique ~]# telnet 192.168.240.37 65123
Trying 192.168.240.37...
Connected to 192.168.240.37.
Escape character is '^]'.
Enter your name:
Bob Smith
Your name is Bob Smith
Connection closed by foreign host.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!