Sha256: 787aeb5e3c794d05132beaefe4100c91bfed163bc17af053f1874898ed175397
Contents?: true
Size: 908 Bytes
Versions: 4
Compression:
Stored size: 908 Bytes
Contents
require_relative "../transport.rb" require 'socket' class StormyCloudTCPTransport < StormyCloudTransport def initialize_server @server = TCPServer.new @stormy_cloud.config(:port) @server_thread = Thread.new do loop do Thread.start(@server.accept) do |client| client.puts handle(client.gets) end end end end def kill_server @server_thread.kill end def raw_send_message(string) begin s = TCPSocket.new(@stormy_cloud.server, @stormy_cloud.config(:port)) s.puts string res = s.gets s.close res rescue @errors ||= 0 @errors += 1 if @errors <= 5 STDERR.puts "An error occurred while contacting the server, trying again." sleep 1 raw_send_message(string) else STDERR.puts "Could not contact the server, exiting." exit end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
stormy-cloud-0.1.1 | lib/transports/tcp.rb |
stormy-cloud-0.1.0 | lib/transports/tcp.rb |
stormy-cloud-0.0.9 | lib/transports/tcp.rb |
stormy-cloud-0.0.8 | lib/transports/tcp.rb |