Created
July 21, 2014 19:29
-
-
Save kernelp4nic/3e06ff71de3f0e74cd42 to your computer and use it in GitHub Desktop.
luanode http/https connection (luanode http_test.lua secure)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local net = require "luanode.net" | |
local host = "userstream.twitter.com" | |
local secure = process.argv[1] == "secure" | |
if secure then | |
console.log("Using secure connection (HTTPS)") | |
local c = net.createConnection(443, host) | |
c:on("connect", function() | |
console.log("connected") | |
c:setSecure() | |
end) | |
c:on("secure", function() | |
c:write("GET / HTTP/1.1\r\nHost: "..host .. "\r\n\r\n") | |
end) | |
c:on("data", function(_, data) | |
console.log("got", data) | |
end) | |
else | |
console.log("Using unsecure connection (HTTP)") | |
local c = net.createConnection(80, host) | |
c:on("connect", function() | |
console.log("connected") | |
c:write("GET / HTTP/1.1\r\nHost: "..host .. "\r\n\r\n") | |
end) | |
c:on("data", function(_, data) | |
console.log("got", data) | |
end) | |
end | |
process:loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment