[英]How to open a port in Windows using Ruby?
我的Windows系统启用了防火墙。
我想允许特定端口上的传入连接(例如:4546)。
有一个红宝石图书馆可以帮助我做到这一点吗?
详细信息:我有一个在端口4546上运行的sinatra应用程序(网络服务器)。我需要关闭防火墙才能正常工作。 我正在寻找一种不将端口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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.