0

无法TCPSocket连接到TCPServer

客户

require 'socket'
require 'io/console'

TCPSocket.open('127.0.0.1', '2000') { |socket|
    #socket.puts('abcdefghijklmn')
    puts socket.read
}

服务器

require 'socket'                # Get sockets from stdlib

server = TCPServer.open(2000)   # Socket to listen on port 2000
loop {                          # Servers run forever
    Thread.start(server.accept) do |client|
        client.puts(Time.now.ctime) # Send the time to the client
        client.puts "Closing the connection. Bye!"
        client.close                # Disconnect from the client
    end
}

错误:

send_socket.rb:4:in `initialize': No connection could be made because the target machine actively refused it. - connect(2) (Errno::ECONNREFUSED)
        from send_socket.rb:4:in `open'
        from send_socket.rb:4:in `<main>'

当连接到 IIS 正在监听的端口 80 时,TCPSocket 工作正常,所以我认为 TCPServer 示例有问题。

关闭防火墙没有帮助。此外 - 当我停止 IIS 并将 TCPServer 设置为端口 80 时,错误是相同的。

4

0 回答 0