ruby - How do I know what ports are on my Macbook? -
i'm trying go through particular code illustration "the grounded rubyist" regarding tcpserver , threads. code below:
require 'socket' server = tcpserver.new(3939) connect = server.accept connect.puts "hi. here's date." connect.puts 'date' connect.close server.close
how know port on macbook? docs has 2000
in example. however, when seek both of these numbers code doesn't execute, continues hang indefinitely.
how can check if these numbers verified ports? tried telnetting port number , connection refused everytime.
server.accepts
waits client connect server. if not happen, keeps waiting. run code, open terminal , type:
require 'socket' s = tcpsocket.new 'localhost', 3939
at point create tcpsocket, connect server. cause rest of code execute. can check socket:
while line = s.gets # read lines socket puts line # , print them end
ruby
No comments:
Post a Comment