01-28-2015, 11:29 PM
Ooooh, that was quite fast The first actual usage of the Lua API is working:
And this is the complete code from the plugin:
Code:
[8863cdd6|14:26:22] Startup complete, took 6040ms!
net client
[af4780c4|14:26:29] Executing console command: "net client"
[af4780c4|14:26:29] Client connection request queued.
[aac7ff14|14:26:29] Connected to google.com:80. Sending HTTP request for front page.
[aac7ff14|14:26:32] Received data from google.com:80:
HTTP/1.0 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Location: http://www.google.cz/?gfe_rd=cr&ei=hePIVKjQM-ik8wfh0oGYAg
Content-Length: 258
Date: Wed, 28 Jan 2015 13:26:29 GMT
Server: GFE/2.0
Alternate-Protocol: 80:quic,p=0.02
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.cz/?gfe_rd=cr&ei=hePIVKjQM-ik8wfh0oGYAg">here</A>.
</BODY></HTML>
And this is the complete code from the plugin:
function HandleConsoleNetClient(a_Split) -- Get the address to connect to: local Host = a_Split[3] or "google.com" local Port = a_Split[4] or 80 -- Create the callbacks "personalised" for the address: local Callbacks = { OnConnected = function (a_Link) LOG("Connected to " .. Host .. ":" .. Port .. ". Sending HTTP request for front page.") a_Link:Send("GET / HTTP/1.0\r\nHost: " .. Host .. "\r\n\r\n") end, OnError = function (a_ErrorCode, a_ErrorMsg) LOG("Connection to " .. Host .. ":" .. Port .. " failed: " .. a_ErrorCode .. " (" .. a_ErrorMsg .. ")") end, OnReceivedData = function (a_Data) LOG("Received data from " .. Host .. ":" .. Port .. ":\r\n" .. a_Data) end, } -- Queue a connect request: local res = cNetwork:Connect(Host, Port, Callbacks) if not(res) then LOGWARNING("cNetwork:Connect call failed immediately") return true end return true, "Client connection request queued." end