簡體   English   中英

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

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM