目录
telnet
gem install net-telnet
- server
#!/usr/bin/ruby
#encoding:UTF-8
# my_server.rb
require 'text_protocols'
TextProtocols.start do
cmd "say-hello" do
"Hello #{params[:name]}"
end
end
- client
#!/usr/bin/ruby
# encoding: utf-8
require 'net/telnet'
tn = Net::Telnet::new('Host' => '127.0.0.1',
'Port' => 5000,
'Telnetmode' => true)
tn.cmd("say-hello name=zhangsang\n") do |c|
puts c
end
[maisipu@192 learn]$ /bin/sh /tmp/geany_run_script_L6FJ71.sh
Hello zhangsang
- http client
#!/usr/bin/ruby
# encoding: utf-8
require 'net/telnet'
tn = Net::Telnet::new('Host' => 'www.hn.chinanews.com.cn',
'Port' => 80,
'Telnetmode' => false)
tn.cmd("GET http://www.hn.chinanews.com.cn/news/hwmtkhn/2023/0626/474786.html \n HTTP/1.1 \n") do |c|
puts c
end
标签:bin,do,end,编程,网络,telnet,tn,ruby
From: https://www.cnblogs.com/waterruby/p/17535629.html