1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package.cpath = package.cpath .. ";libs/?.dll"
package.path = package.path .. ";libs/lua/?.lua"
require "socket"
foo = socket.protect(function()
	-- connect somewhere
	local c = socket.try(socket.connect("google.com", 80))
	-- create a try function that closes 'c' on error
	local try = socket.newtry(function() c:close() end)
	-- do everything reassured c will be closed
	try(c:send("hello there?\r\n"))
	local answer = try(c:receive())
	print(answer)
	try(c:send("good bye\r\n"))
	c:close()
end)
foo()