刚在ECS上创建了一个实例(1CPU2G),IP地址为120.76.118.208。在ECS服务器上安装了RUBY,创建了如下服务器端软件并通过ECS服务器端的命令行运行:
require "socket"
def testTCPServer
server = TCPServer.new 2010 # Server bound to port 2010
loop do
client = server.accept # Wait for a client to connect
client.puts "Hello again !"
client.puts "Some thing from Server"
puts client.gets
client.close
end
end
testTCPServer
同时在我自己的电脑上创建并运行如下RUBY程序 :
require 'socket'
def testTcpClient
s = TCPSocket.new '120.76.118.208', 2010
s.puts "Some thing from CLIENT"
while line = s.gets # Read lines from socket
puts line # and print them
end
s.close # close socket when done
end
testTcpClient
但是运行的结果显示无法连接,如下。请问是什么问题?
client.rb:4:in `initialize': No connection could be made because the target machine actively refused
it. - connect(2) for "120.76.118.208" port 2010 (Errno::ECONNREFUSED)
我看ECS服务器上的防火墙是关闭的。
谢谢。
-------------------------
-------------------------
-------------------------
TCP port 2010 (unknown service): NOT LISTENING
portqry.exe -n 120.76.118.208 -e 2010 -p TCP exits with return code 0x00000001.
-------------------------
require "socket"
def testTCPServer
server = TCPServer.new 2010 # Server bound to port 2010
require "socket"
def testTCPServer
server = TCPServer.new("120.76.118.208", 2010) # Server bound to port 2010
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。