From: Andreas K. <and...@gm...> - 2009-10-25 14:19:24
|
Great it works now! lostgallifreyan wrote: > If I carry on with this, the main thing I need to know is how to set > up wxLua as a simple local proxy so I can design a web filter. I'll > sort the filter details in my own time, but if someone can help me > with a minimal template for the connections part of that, please do. > Now that I've seen something work, I'll give it the effort it > deserves if someone can give me that core template for connecting > wxLua as local proxy between a browser and the net. Did you consider using Lua and LuaSocket [1] instead of wxLua? I think this would simplify the whole socket and proxy programming. Here is some example code: -- load namespace local socket = require "socket" -- create a TCP socket and bind it to the local host, at port 8080 local server = assert(socket.bind("*", 8080)) while 1 do -- wait for a connection from any client local client = server:accept() -- receive the line local line, err = client:receive() -- if there was no error, send a simple webpage as example if not err then client:send([[ <html> <body> <h1>Proxy Test</h1> </body> </html> ]]) print(line) end -- done with client, close the object client:close() end If your browser uses the proxy (as HTTP proxy), it will send something like "GET http://www.google.com HTTP/1.1". Then you can download and process the webpage using LuaSocket and send the result with client:sent(). You can use LuaSocket with wxLua as well. [1] http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/home.html |