A semantic search engine for source code https://bitshift.benkurtovic.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

38 lines
940 B

  1. require 'socket'
  2. require File.expand_path('../parser.rb', __FILE__)
  3. def pack_int(i)
  4. bytes = []; mask = 255
  5. while bytes.length < 4
  6. bytes.unshift (i & mask)
  7. i = i >> 8
  8. end
  9. return bytes.pack('cccc')
  10. end
  11. def start_server(port_number)
  12. server = TCPServer.new port_number
  13. puts "Ruby Server listening on port #{port_number}\n"
  14. loop do
  15. # Start a new thread for each client accepted
  16. Thread.start(server.accept) do |client|
  17. begin
  18. # Get the amount of data to be read
  19. size = (client.readline).to_i
  20. p = Bitshift::Parser.new client.read(size)
  21. # Get the parsed result
  22. symbols = p.parse
  23. client.puts pack_int(symbols.length)
  24. client.puts symbols
  25. ensure
  26. # Close the socket
  27. client.close
  28. end
  29. end
  30. end
  31. end