Type:
Class

TCPServer represents a TCP/IP server socket.

A simple TCP server may look like:

require 'socket'

server = TCPServer.new 2000 # Server bind to port 2000
loop do
  client = server.accept    # Wait for a client to connect
  client.puts "Hello !"
  client.puts "Time is #{Time.now}"
  client.close
end

A more usable server (serving multiple clients):

require 'socket'

server = TCPServer.new 2000
loop do
  Thread.start(server.accept) do |client|
    client.puts "Hello !"
    client.puts "Time is #{Time.now}"
    client.close
  end
end
accept

tcpserver.accept => tcpsocket Instance Public methods

2015-05-17 06:37:11
accept_nonblock

tcpserver.accept_nonblock => tcpsocket Instance Public methods Accepts an

2015-05-17 06:44:00
new

TCPServer.new([hostname,] port) => tcpserver Class Public methods

2015-05-17 06:30:33
listen

socket.listen( int ) => 0 Instance Public methods Listens for connections

2015-05-17 06:49:07
sysaccept

tcpserver.sysaccept => file_descriptor Instance Public methods Returns a

2015-05-17 06:54:38