Class: ContentServer::ContentDataSender

Inherits:
Object
  • Object
show all
Defined in:
lib/content_server/content_receiver.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ ContentDataSender

Returns a new instance of ContentDataSender.



32
33
34
35
36
# File 'lib/content_server/content_receiver.rb', line 32

def initialize host, port
  @host = host
  @port = port
  open_socket
end

Instance Method Details

#open_socketObject



38
39
40
41
# File 'lib/content_server/content_receiver.rb', line 38

def open_socket
  Log.debug1("Connecting to content server %s:%s.", @host, @port)
  @tcp_socket = TCPSocket.new(@host, @port)
end

#send_content_data(content_data) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/content_server/content_receiver.rb', line 43

def send_content_data content_data
  open_socket if @tcp_socket.closed?
  marshal_data = Marshal.dump(content_data)
  Log.debug2("Marshaled size: %s.", marshal_data.length)
  data_size = [marshal_data.length].pack("l")
  if data_size.nil? || marshal_data.nil?
    Log.debug2('Send data is nil!!!!!!!!')
  end
  @tcp_socket.write data_size
  @tcp_socket.write marshal_data
end