From: tammy roberts2 Date: 2012-08-20T18:57:16+09:00 Subject: Re: TCPserver how to signal EOT Hi Robert, it is me again, my computer crashed and I lost my login information. Here is what I am using right now, it seems to be working fine, but maybe you see problems with it or a way to improve. Also maybe it will help someone else out who is struggling with the same problem I was. class Networking def initialize @settings = Settings.new end def listen(server) loop do Thread.start(server.accept) do |client| data_received = [] total_received = 0 incoming_data_size = client.recvfrom( 4 )[0].unpack('N*')[0] loop do section_size = client.recvfrom( 4 )[0].unpack('N*')[0] message_section = "" loop do message_section << client.recvfrom( section_size )[0] break if message_section.bytesize == section_size end data_received << message_section total_received += 4 + message_section.bytesize break if total_received == incoming_data_size end yield(data_received, client) end end end def send_data(socket, message) forward_message = [message.bytesize].pack('N*') + message socket.send(forward_message, 0) yield(socket) end def get_reply(socket) incoming_data_size = socket.recvfrom( 4 )[0].unpack('N*')[0] section_size = socket.recvfrom( 4 )[0].unpack('N*')[0] reply = "" loop do reply << socket.recvfrom( section_size )[0] break if reply.bytesize == incoming_data_size - 4 end yield(reply, socket) end end -- Posted via http://www.ruby-forum.com/.