def split_to_chunks(string, bytesize) arr = [] until string.empty? arr << string.slice!(0..bytesize) end return arr end def sockSend(sock, message) chunk_size = 1024 messageChunks = split_to_chunks(message, chunk_size) messageChunks.each { |chunk| sleep(0.3) sock.puts chunk } sock.puts "<END_OF_SOCKET_DATA>" end
def sockRead(sock) full_result = "" chunk = "" chunk_size = 1024 while true do chunk = sock.recv(chunk_size) if chunk.chomp == "<END_OF_SOCKET_DATA>" then break end sleep(0.2) full_result = full_result + chunk end return full_result.chomp end
"<END_OF_SOCKET_DATA>"
puts
\n
send
sendmsg
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)