Eleanor McHugh wrote:
> Post us some code so that we can see what you're doing and make
> relevant suggestions.

Note: I acknowledge some code was copied and then modified.  The server 
script was kind of made last second just to test this out.

# server.rb
#
require 'socket'
require 'bin_protocol'

dts = TCPServer.new('localhost', 20000 )
puts "Entering loop"
loop do
  Thread.start(dts.accept) do |s|
    puts "In loop!"
    sock = BinProtocol.new( s )
    print(s, " is accepted\n")
    sock.send_data("Welcome to the Swat Server!")
    print(s, "says '#{sock.get_data}")
    sock.send_data("Can I get some help?")
    print sock.get_data
    sock.send_data("Goodbye!")
    print(s, " is gone\n")
    s.close
  end
end

# client.rb
#
require 'socket'
require 'bin_protocol'

s = TCPSocket.new( 'localhost', 20000 )
sock = BinProtocol.new( s )
print sock.get_data
sock.send_data("Why thank you Server!")
print sock.get_data
sock.send_data( File.new("help.txt", "r").readlines.to_s )
print sock.get_data
s.close

# bin_protocol.rb
#
require 'socket'
require 'bit-struct'

class BinProtocol

  class SizeStruct < BitStruct
    unsigned :message_length, 4*8, "Message Length", :endian => :network
  end # SizeStruct

  class DataStruct < BitStruct
    rest :message, "String containing data"
  end

  def initialize( tcp_sock )
    @tcp_sock = tcp_sock
  end

  def send_data( data_str )
    data_struct = DataStruct.new
    size_struct = SizeStruct.new
    data_struct.message = data_str
    size_struct.message_length = DataStruct.round_byte_length
    @tcp_sock.write( size_struct.to_s )
    @tcp_sock.write( data_struct.to_s )
  end

  def get_data
    size_struct = SizeStruct.new( @tcp_sock.recv(4).to_s )
    data_struct = DataStruct.new( @tcp_sock.recv( 
size_struct.message_length ) )
    return data_struct.to_s
  end

end

and help.txt is just a simple, multiple line, text file.  Just note that 
I am using the Bit-Struct gem and I am getting a NoMemoryError from 
get_data when my computer says I should have plenty of memory to run 
this.  Also I took the binary route because another part of the program 
not shown here is required to deal with binary networking streams 
anyways, so I figured I could just apply one to the other.  So... help?
-- 
Posted via http://www.ruby-forum.com/.