require 'pp' class ClientTCPSocketPackagedPipe MAX_PKG_SIZE=100000 def initialize(host,port) @socket=TCPSocket.new(host,port) @socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) @inPackages=[] recvLoop end def writePackage(str) @socket.write(str) @socket.flush end def recvPackage @inPackages.shift end private def recvLoop Thread.new { begin loop do data=@socket.recv(MAX_PKG_SIZE) if data.length>0 @inPackages << data else break end end rescue Object=>e pp e,e.backtrace end } end end class ServerTCPSocketPackagedPipe attr_accessor :socket class Server0 pp "GOT DATA (at #{@conn.addr}) #{curdata.length}" else puts "NO MORE DATA" break end @client.push(curdata) end rescue Exception=>e #glog e,e.backtrace,self #unless e.inspect.to_s=="#" pp e,e.backtrace,self #end end end end def initialize(listen,port) @socket=nil @server=Server.new(listen,port,self) @packages=[] end def writePackage(str) end end