You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ruby TCPServer跨IP访问咨询:Mac High Sierra替代Telnet方案

Hey there! Let's figure out how to connect to your partner's Ruby TCP server from your Mac High Sierra, since telnet isn't available by default. Here's a step-by-step breakdown:

1. Grab the Server Device's Network IP Address

First, you need your partner's laptop's local network IP (not 127.0.0.1—that only works for connections on the same device). Here's how to find it:

  • On Mac/Linux: Open Terminal and run ifconfig (or ip addr on newer Linux distros). Look for the inet line under the active network interface (usually en0 for Wi-Fi) — it’ll look like 192.168.1.105.
  • On Windows: Open Command Prompt and run ipconfig, then find the "IPv4 Address" under your active network adapter.
2. Connect Without Telnet: Use These Alternatives

Since telnet isn’t enabled out of the box, here are three reliable options to connect to the server:

Option 1: Use nc (Netcat) — Built into Mac

Mac comes pre-installed with Netcat (nc), a versatile network tool. Open your Terminal and run:

nc [partner's-ip] 2345

For example, if their IP is 192.168.1.105, run nc 192.168.1.105 2345. You’ll immediately see the server’s "What do you say?" prompt and can start sending messages until you type quit.

Option 2: Install Telnet via Homebrew

If you prefer to use telnet, you can install it easily with Homebrew:

  1. First install Homebrew (if you don’t have it already):
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  2. Then install telnet:
    brew install telnet
    

Once installed, connect with:

telnet [partner's-ip] 2345

Option 3: Write a Simple Ruby Client Script

Since you’re already working with Ruby, create a custom client script. Save this as tcp_client.rb:

require 'socket'

# Replace with your partner's actual IP address
server_ip = "192.168.1.105"
socket = TCPSocket.new(server_ip, 2345)

# Receive the initial message from the server
puts socket.gets.chomp

loop do
  print "You: "
  input = gets.chomp
  socket.puts input

  response = socket.gets.chomp
  puts "Server: #{response}"

  break if input == "quit"
end

socket.close

Run it with ruby tcp_client.rb, and you’ll have a fully functional client to interact with the server.

3. Critical Network Checks to Avoid Issues
  • Same Local Network: Ensure both laptops are connected to the same Wi-Fi or wired network. If they’re on different networks, you’ll need port forwarding on the server’s router (stick to the same network for simplicity first).
  • Firewall Settings: On your partner’s laptop, make sure the firewall isn’t blocking port 2345. For Mac, go to System Preferences > Security & Privacy > Firewall > Firewall Options, then add an exception for Terminal or allow incoming connections on port 2345.
  • Verify Server is Listening: On the server’s Terminal, run lsof -i :2345 — you should see a line for ruby with TCPSERVER listed, confirming the server is active and waiting for connections.

内容的提问来源于stack exchange,提问作者Robert Faldo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:36:44