如何使用Ruby在Windows中打开端口?

如何使用Ruby在Windows中打开端口?,ruby,windows,firewall,Ruby,Windows,Firewall,我的windows系统已启用防火墙 我希望允许特定端口上的传入连接(例如:4546) 有没有ruby库可以帮我做到这一点 详情: 我有一个sinatra应用程序(Web服务器)在端口4546上运行。我需要关闭防火墙才能让它工作。 我正在寻找一种不将端口4546保留在防火墙列表下的方法。是的,您可以使用以下方法: require 'socket' # Get sockets from stdlib server = TCPServer.open(4546) # So

我的windows系统已启用防火墙

我希望允许特定端口上的传入连接(例如:4546)

有没有ruby库可以帮我做到这一点

详情: 我有一个sinatra应用程序(Web服务器)在端口4546上运行。我需要关闭防火墙才能让它工作。
我正在寻找一种不将端口4546保留在防火墙列表下的方法。

是的,您可以使用以下方法:

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
}

看起来很有趣。确切的问题是我有一个运行在端口4546上的web服务器。但我需要关闭防火墙才能让它工作。这行吗?您必须为此端口向防火墙添加一个例外。在命令行上激发这些命令,或从Ruby运行:netsh Firewall add portopening protocol=TCP port=4546 name=“Web服务器(TCP 4546)”mode=ENABLE netsh Firewall reset