简体   繁体   中英

Unable to create an EXE file from Ruby script

I am unable to create an EXE file from Ruby script.

require 'socket'

class Server
  def initialize(ip, port)
    @server = TCPServer.open(ip, port)
    @clients = Array.new
    run
  end

  def run
    loop {
      Thread.start(@server.accept) do |client|
        @clients << client
        client.puts 'Connection established'
        listen_user_messages(client)
      end
    }.join
  end

  def listen_user_messages(client)
    loop {
      msg = client.gets.chomp
      @clients.each do |other_client|
        if other_client != client
          other_client.puts "#{msg}"
        end
      end
    }
  end
end

Server.new('localhost', 19937)

I'm trying to run the following command:

ocra server.rb

but it freezes on the message

=== Loading script to check dependencies

I've also tried to use exerb:

ruby exerb server.rb

It builds an exe file, but I am unable to use it:

server.rb:1:in `require': No such file to load -- socket (LoadError) from server.rb:1

require 'socket'
require 'rubygems'
exit if Object.const_defined?(:Ocra) #allow ocra to create an exe without executing the entire script

Add the above to your script, this should allow it to generate. Ocra cannot see ruby gems and other files at times if you don't include 'rubygems'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM