ws_url = "ws://demos.kaazing.com/echo"
DLL_PATH = "../websocket.dll"
WS_CONNECT = Win32API.new(DLL_PATH, "ws_connect", "ip", "i")
WS_UPDATE = Win32API.new(DLL_PATH, "ws_update", "i", "i")
WS_DATA = Win32API.new(DLL_PATH, "ws_data", "pp", "v")
WS_SEND = Win32API.new(DLL_PATH, "ws_send", "ip", "v")
WS_CLOSE = Win32API.new(DLL_PATH, "ws_close", "i", "v")
raise if WS_CONNECT.call(0, ws_url) < 0
f = File.open("../result.txt", "w")
30.times do |i|
WS_SEND.call(0, "hi! #{i}")
end
120.times do |i|
Graphics.update
n = WS_UPDATE.call(0)
buffer_len = n / 1024
recv_num = n % 1024
if recv_num > 0
buffer = "\0" * buffer_len
lens = "\0" * 4 * recv_num
WS_DATA.call(buffer, lens)
s = 0
f.puts "recv #{recv_num} at frame No.#{i}:"
lens.unpack("L*").each do |len|
f.puts "#{buffer[s...s + len]}"
s += len
end
end
end
WS_CLOSE.call(0)
f.close
exit
ws_url = "ws://demos.kaazing.com/echo"
DLL_PATH = "../websocket.dll"
WS_CONNECT = Win32API.new(DLL_PATH, "ws_connect", "ip", "i")
WS_UPDATE = Win32API.new(DLL_PATH, "ws_update", "i", "i")
WS_DATA = Win32API.new(DLL_PATH, "ws_data", "pp", "v")
WS_SEND = Win32API.new(DLL_PATH, "ws_send", "ip", "v")
WS_CLOSE = Win32API.new(DLL_PATH, "ws_close", "i", "v")
raise if WS_CONNECT.call(0, ws_url) < 0
f = File.open("../result.txt", "w")
30.times do |i|
WS_SEND.call(0, "hi! #{i}")
end
120.times do |i|
Graphics.update
n = WS_UPDATE.call(0)
buffer_len = n / 1024
recv_num = n % 1024
if recv_num > 0
buffer = "\0" * buffer_len
lens = "\0" * 4 * recv_num
WS_DATA.call(buffer, lens)
s = 0
f.puts "recv #{recv_num} at frame No.#{i}:"
lens.unpack("L*").each do |len|
f.puts "#{buffer[s...s + len]}"
s += len
end
end
end
WS_CLOSE.call(0)
f.close
exit