TCPSocket connection reset by peer

#1
Mã:
require 'socket'
socket = TCPSocket.open('stream-api.betfair.com', '443')
while line = socket.gets
  puts line.chop
end
socket.close
I should receive something like {"op":"connection","connectionId":"002-230915140112-174"}
but I receive Connection reset by peer which

means the remote end would have sent a reset packet (RST) to kill the connection without an orderly shutdown (close). In that case you know it was the peer(client).
betfair included a nodejs example and also csharp/java examples

Any help is much appreciated. Thanks!
 

Admin

Administrator
Thành viên BQT
#2
First thing, you should replace the string '443' by an integer :
Mã:
TCPSocket.open('stream-api.betfair.com', 443)
Anyway, it seems to be related with the SSL negociation. Using this method, I works.
Mã:
require 'socket'
require 'openssl'

host = 'stream-api.betfair.com'
port = 443

socket = TCPSocket.open(host,port)
ssl_context = OpenSSL::SSL::SSLContext.new()
ssl_context.ssl_version = :SSLv23
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
ssl_socket.sync_close = true
ssl_socket.connect
while line = ssl_socket.gets
  p line
end
ssl_socket.close
Result :
Mã:
"{\"op\":\"connection\",\"connectionId\":\"001-151118094105-259478\"}\r\n"
Dealing with SSL/TLS protected connection is sometime quite verbose with Ruby. In the example you gave, in NodeJS, the hint is the first line :
Mã:
var tls = require('tls');
 

Từ khóa phổ biến

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top