Platinum Partner

Simple Ruby Web Service

Simple ruby web service with socket

Server

require 'socket'                				# Get sockets from stdlib
server = TCPServer.open(2000)   				# Socket to listen on port 2000
loop {                          				# Servers run forever
  Thread.start(server.accept) do |client|
    client.puts(Time.now.ctime) 				# Send the time to the client
	client.puts "Closing the connection. Bye!"
    client.close                				# Disconnect from the client
  end
}


client

require 'socket'      					# Sockets are in standard library

hostname = 'localhost'
port = 2000
s = TCPSocket.open(hostname, port)

while line = s.gets   					# Read lines from the socket
  puts line.chop      					# And print with platform line terminator
end
s.close               					# Close the socket when done

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}