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.
 
 
 
 
 
 

34 line
768 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. server = TCPServer.new 5003
  12. loop do
  13. # Start a new thread for each client accepted
  14. Thread.start(server.accept) do |client|
  15. begin
  16. # Get the amount of data to be read
  17. size = (client.readline).to_i
  18. p = Bitshift::Parser.new client.read(size)
  19. # Get the parsed result
  20. symbols = p.parse
  21. client.puts pack_int(symbols.length)
  22. client.puts symbols
  23. ensure
  24. # Close the socket
  25. client.close
  26. end
  27. end
  28. end