2011-03-17 56 views
0

我的Windows系統啓用了防火牆。如何使用Ruby在Windows中打開一個端口?

我想允許特定端口上的傳入連接(比如:4546)。

有沒有一個紅寶石庫可以幫助我做到這一點?

細節: 我有一個運行在端口4546上的sinatra應用程序(web服務器)。爲了使它工作,我需要關閉防火牆。 我正在尋找一種方法來防止端口4546在防火牆列表下。

回答

1

是的,你可以這樣做與此:

require 'socket'    # Get sockets from stdlib 

server = TCPServer.open(4546) # Socket to listen on port 4546 
loop {       # Servers run forever 
    client = server.accept  # Wait for a client to connect 
    client.puts(Time.now.ctime) # Send the time to the client 
    client.puts "Closing the connection. Bye!" 
    client.close     # Disconnect from the client 
} 
+0

看起來很有趣。 那麼確切的問題是我有一個運行在端口4546上的web服務器。但我需要關閉防火牆才能工作。 這項工作? – 2011-03-17 06:08:58

+0

您必須爲此端口向防火牆添加例外。 – 2011-03-17 06:13:13

+0

我該怎麼做? – 2011-03-17 06:14:20

相關問題