Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Parse XML stream from TCP socket
- require 'socket'
- require 'timeout'
- username = "usernamern"
- password = "passwordrn"
- port = 4500
- server = 'xmlfeed.website.com'
- tcp_client = TCPSocket.new(server, port)
- all_data = []
- value = 0
- while true
- partial_data = tcp_client.recv(1012)
- if partial_data.length == 0
- break
- end
- all_data << partial_data
- puts(all_data)
- if value == 0
- tcp_client.puts(username)
- value = 1
- end
- if value == 1
- tcp_client.puts(password)
- value = 2
- end
- if all_data.to_s.chomp.casecmp( "Starting Feed")
- value = 3
- puts "Begin the feed"
- end
- if value == 3
- # Parse the data using LibXML
- # this is the part I'm not sure how to approach
- puts(all_data)
- end
- end
- tcp_client.close
- puts all_data.join()
Add Comment
Please, Sign In to add comment