A semantic search engine for source code https://bitshift.benkurtovic.com/
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

parse_server.rb 768 B

123456789101112131415161718192021222324252627282930313233
  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