Explorar el Código

Add Rakefile task for running ruby parse server.

tags/v1.0^2
Benjamin Attal hace 10 años
padre
commit
be7c871cc9
Se han modificado 2 ficheros con 23 adiciones y 15 borrados
  1. +5
    -0
      parsers/ruby/Rakefile
  2. +18
    -15
      parsers/ruby/lib/parse_server.rb

+ 5
- 0
parsers/ruby/Rakefile Ver fichero

@@ -0,0 +1,5 @@
require File.expand_path('../lib/parse_server.rb', __FILE__)

task :start_server do |t|
start_server
end

+ 18
- 15
parsers/ruby/lib/parse_server.rb Ver fichero

@@ -12,22 +12,25 @@ def pack_int(i)
return bytes.pack('cccc')
end

server = TCPServer.new 5003

loop do
# Start a new thread for each client accepted
Thread.start(server.accept) do |client|
begin
# Get the amount of data to be read
size = (client.readline).to_i
p = Bitshift::Parser.new client.read(size)
# Get the parsed result
symbols = p.parse
client.puts pack_int(symbols.length)
client.puts symbols
ensure
# Close the socket
client.close
def start_server
server = TCPServer.new 5003

loop do
# Start a new thread for each client accepted
Thread.start(server.accept) do |client|
begin
# Get the amount of data to be read
size = (client.readline).to_i
p = Bitshift::Parser.new client.read(size)
# Get the parsed result
symbols = p.parse
client.puts pack_int(symbols.length)
client.puts symbols
ensure
# Close the socket
client.close
end
end
end
end

Cargando…
Cancelar
Guardar