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