My windows system has t开发者_运维技巧he firewall enabled.
I would like to allow incoming connections on a particular port (say: 4546).
Is there a ruby library that can help me do this ?
Detail: I have a sinatra application (webserver) running on port 4546. I needed to bring down the firewall in order for it to work. I am looking for a way to not keep the port 4546 under the firewall list.
Yes, you can do that with this:
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
}
精彩评论