Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6474529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:35:51+00:00 2026-05-25T06:35:51+00:00

I have such code on python connect to some software by socket: import socket,

  • 0

I have such code on python connect to some software by socket:

import socket, ssl

host = '127.0.0.1'
port = 8963
sert_key = '../keys/key.pem'

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, True)
sock.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, True)
sock.settimeout(30.5)
sock.connect((host, port))
sock = ssl.wrap_socket(sock, server_side=True, certfile=sert_key,
ssl_version=ssl.PROTOCOL_TLSv1)


cert = "hello"

cert = cert.encode('utf-8')
req = ('%08x'%len(cert))+cert
sock.sendall(req)
print sock.recv(4096)

Output: “OK”, so its work.

I try to convert such code on ruby, but it doesn’t work:

require 'socket'
require 'openssl'

host = '127.0.0.1'
port = 8963
sert_key = '../keys/key.pem'

socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
address = Socket.pack_sockaddr_in(port, host)
socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
socket.setsockopt(Socket::SOL_TCP, Socket::TCP_NODELAY, true)
socket.connect(address)

#socket = TCPSocket.new(host, port) # not help also

ssl_context = OpenSSL::SSL::SSLContext.new(:TLSv1)
ssl_context.cert = OpenSSL::X509::Certificate.new(File.open(sert_key))
ssl_context.key = OpenSSL::PKey::RSA.new(File.open(sert_key))
ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
ssl_socket.sync_close = true
ssl_socket.connect


sert = "hello"                                                                                                                                                                                            
sert = sert.force_encoding('UTF-8')                                                                                                                                                                        
req = sprintf("%08x", sert.length) + sert                                                                                                                                                                  
ssl_socket.write(req)                                                                                                                                                                                                                                                                                                                                                                                      
puts ssl_socket.read(4096) 

But I have such error:

test1.rb:30:in `connect’: SSL_connect returned=1 errno=0 state=SSLv3 read server hello B: bad message type (OpenSSL::SSL::SSLError)

Help me please port this code on ruby. I don’t understand what I miss (where difference in codes).

P.S. Sorry, but software to which I want to connect not for sharing for now 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:35:52+00:00Added an answer on May 25, 2026 at 6:35 am

    Seems like you should use something like this:

    require 'socket'
    require 'openssl'
    
    host = '127.0.0.1'
    port = 8963
    sert_key = '../keys/key.pem'
    
    socket = TCPSocket.new(host, port) # not help also
    
    ssl_context = OpenSSL::SSL::SSLContext.new(:TLSv1)
    ssl_context.cert = OpenSSL::X509::Certificate.new(File.open(sert_key))
    ssl_context.key = OpenSSL::PKey::RSA.new(File.open(sert_key))
    ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
    ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
    ssl_socket.sync_close = true
    ssl_socket.accept
    
    sert = "hello"                                                                                                                                                                                            
    sert = sert.force_encoding('UTF-8')                                                                                                                                                                        
    req = sprintf("%08x", sert.length) + sert                                                                                                                                                                  
    ssl_socket.write(req)
    puts ssl_socket.sysread(4096)
    

    EDIT: Updated code yet another time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such code in Python: def send_start(self, player): for p in self.players: player[socket].send_cmd('<player
So I have some openGL code (such code for example) /* FUNCTION: YCamera ::
I was wondering, if I have some code such as: $result = $db->query($sql); //
I have such code (Python 2.5, GAE dev server): try: yt_service.UpgradeToSessionToken() // this line
I have one question, I have such code this._engine = Python.CreateEngine(); ScriptSource source =
I have such code: <h:inputText id=input value=#{bean.input}> <f:convertNumber /> <rich:ajaxValidator event=onblur /> </h:inputText> I
I have such code in my JSF template: <h:form> <table id=users cellspacing=0> <a4j:repeat var=person
i have such code var prj = _dataContext.Project.FirstOrDefault(p => p.isPopular == true); if (prj
I have such code: function allValid() { $('input').each(function(index) { if(something) { return false; }
For reference, the code is for the motorola 68008. Say I have code such

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.