admin管理员组文章数量:1400311
I never really needed to use socket before and just out of curiosity I tried to write a python script as server and another as client. It worked and there is no issue there. In next step, I tried to use systemd.socket and I stuck there. my client always hangs in receiving data. socat and nc return the data with no issue. I appreciate if someone can tell me what am I doing wrong? Hours of googling and talking to chatgpt did not solve the issue. I checked systemd.socket manual and socket module page but no luck there either.
This is the socket unit:
# test.socket
[Unit]
Description = test socket
[Socket]
ListenStream = 8080
Accept = yes
[Install]
WantedBy = sockets.target
service unit:
# [email protected]
[Unit]
Description=test service for socket
[Service]
ExecStart=/usr/bin/python3 /home/myuser/server.py
StandardInput=socket
StandardOutput=socket
server:
#!/usr/bin/python3
import sys
sys.stdout.write(sys.stdin.readline())
and this is my client:
#!/usr/bin/python3
import socket
host = '127.0.0.1'
port = 8080
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.send('Hello')
response = s.recv(1024)
if response:
print("OK")
本文标签: how recieve data using python script from systemdsocketStack Overflow
版权声明:本文标题:how recieve data using python script from systemd.socket - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744222214a2595921.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论