|
|
@@ -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 |