mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Add some socket examples of bidirectional command helpers and pexpect
bidir_cmd_herlper.sh: Bidirectional command helper by socat. bidir_cmd_helper.py: Bidirectional command helper by python and netcat. pexpect-ping.py, pexpect-pong.py: Scripts for throwing Ping-Pong between cross-connected tios.
This commit is contained in:
parent
a9f05a66f7
commit
c25a379fbb
4 changed files with 153 additions and 0 deletions
22
examples/socket/pexpect-ping.py
Executable file
22
examples/socket/pexpect-ping.py
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/python3
|
||||
# In MSYS2, use /mingw64/bin/python3
|
||||
#
|
||||
# Send a "Ping" and wait for a "Pong".
|
||||
# Repeat this process.
|
||||
#
|
||||
|
||||
import pexpect
|
||||
from pexpect import popen_spawn
|
||||
|
||||
child = pexpect.popen_spawn.PopenSpawn("nc -UN /tmp/tio-socket0")
|
||||
|
||||
cnt = 0
|
||||
while True:
|
||||
try:
|
||||
child.sendline(f"Ping {cnt:d}")
|
||||
cnt += 1
|
||||
child.expect(r'Pong \d+[\r\n]+', timeout = 10)
|
||||
except Exception as e:
|
||||
print(type(e))
|
||||
break
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue