Guest User

Untitled

a guest
Sep 11th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. Parse XML stream from TCP socket
  2. require 'socket'
  3. require 'timeout'
  4.  
  5. username = "usernamern"
  6. password = "passwordrn"
  7. port = 4500
  8. server = 'xmlfeed.website.com'
  9.  
  10. tcp_client = TCPSocket.new(server, port)
  11.  
  12.  
  13. all_data = []
  14. value = 0
  15. while true
  16. partial_data = tcp_client.recv(1012)
  17.  
  18. if partial_data.length == 0
  19. break
  20. end
  21. all_data << partial_data
  22. puts(all_data)
  23. if value == 0
  24. tcp_client.puts(username)
  25. value = 1
  26. end
  27. if value == 1
  28. tcp_client.puts(password)
  29. value = 2
  30. end
  31. if all_data.to_s.chomp.casecmp( "Starting Feed")
  32. value = 3
  33. puts "Begin the feed"
  34. end
  35. if value == 3
  36. # Parse the data using LibXML
  37. # this is the part I'm not sure how to approach
  38. puts(all_data)
  39. end
  40. end
  41. tcp_client.close
  42.  
  43. puts all_data.join()
Add Comment
Please, Sign In to add comment