2012-03-12 10 views
1

これは私のルビーサーバーです:ノードnetソケット経由でRuby TCPサーバーを接続する方法は?

require "socket" 

server=TCPServer.open(2000) 

loop{ 
    puts "wait for connect" 
    client=server.accept 
    puts "connect" 
    client.puts(Time.now.ctime) 
    client.close 
} 

と私は仕事の罰金であるルビークライアントwrited:

require "socket" 
s=TCPSocket.open("localhost",2000) 

while line=s.gets 
    puts line.chop 
end 

s.close 

をしかし、私が代わりにノードソケットを使用する場合、私はError: connect ECONNREFUSEDを得ました。

これは私のノードのコードです:

var client, net; 
net = require("net"); 
client = net.createConnection(2000); 
console.log("connected"); 
client.on("data", function (data) { 
    console.log(data); 
}); 
client.on("end", function() { 
    return console.log("client closed"); 
}); 

は、私が行っていた何かが間違っているのですか?

+0

'netstat -anp |の出力は何ですか? grep 2000'? – sarnold

+0

何もありません! – island205

+0

あなたのサーバーはもう稼働していませんか? – sarnold

答えて

0

ポートを2回開くことはできません。サーバーを実行すると、そのポートのlocalhostに接続できません。

関連する問題