From ba567494403b046ba64ac22d979dea31748ab051 Mon Sep 17 00:00:00 2001 From: Denver Gingerich Date: Mon, 20 Apr 2020 22:55:47 +0000 Subject: [PATCH] send JSON data to SGX, but SGX can't handle it yet --- r2s-bwmsgsv2.rb | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/r2s-bwmsgsv2.rb b/r2s-bwmsgsv2.rb index a0385931bd4e814fe9d4b154f59ee80ffbb5918f..9c0815d7e0e6cf5f01d8ca8ef1fd3f185aa52d6e 100755 --- a/r2s-bwmsgsv2.rb +++ b/r2s-bwmsgsv2.rb @@ -89,12 +89,23 @@ while true ',"ts_030_unix-translator_received":' + ts + ',' + timestamps_plus_json_blob - # TODO: fix so sending new_json_blob to SGX, and via POST - response = Net::HTTP.get_response( - URI("https://#{ARGV[1]}:#{ARGV[2]}/r2tst.php") - ) - - puts "TODO - response.code = #{response.code} and body #{response.body}" + uri = URI("http://#{ARGV[1]}:#{ARGV[2]}/") + req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json') + req.body = "{#{new_json_blob}}" # TODO: should just be MSG part (?) + begin + res = Net::HTTP.start(uri.hostname, uri.port) do |http| + http.request(req) + end + # list of exceptions is from https://stackoverflow.com/a/5370726 + rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, + Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, + Net::ProtocolError => e + + puts "TODO problem '#{e}' - now we should try again..." + # TODO: actually try again + else + puts "TODO - res: '#{res.code}' '#{res.message}': '#{res.body}'" + end # if SGX gives back anything but response.code 200, retry 5 times-ish # if SGX failed to respond after retries, email or other notify