Coder Social home page Coder Social logo

nginx-tcp-lua-server's Introduction

nginx-tcp-lua-server

How to build

1. download the special version from openresty.com
    # wget http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz
2. download the special version patch and do patch
    # cp ngx-1.7.10-default_head.patch ngx_openresty-1.7.10.1/bundle/
    # cd ngx_openresty-1.7.10.1/bundle
    # patch -p0 < ngx-1.7.10-default_head.patch
3. make and install 
    # cd ngx_openresty-1.7.10.1
    # ./configure
    # make
    # make install

How to use it

    server {
        listen       80;
        server_name  localhost;
        default_head "GET /demo.html HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n";

        location /demo.html {
            content_by_lua '
                local tcp_req, err = ngx.req.socket(true)
                if not tcp_req then
                    ngx.log(ngx.ERR, "get req socket err: ", err)
                end
                 
                while true do
                    local req_data
                    req_data, err = tcp_req:receive(1)
                    if not req_data then
                        ngx.log(ngx.ERR, "get req_data err: ", err)
                        return
                    end
                 
                    ngx.log(ngx.ERR, "req data:", req_data)
                    tcp_req:send(req_data)
                end
            ';
        }
    }

Pay attention

Its not a pure nginx tcp server. But is more power if you use ngx-lua with this way. It have great compatibility, and you can use 100% api of nginx-lua-module with lastest version.

provide by [email protected]

if you have any question, please let me know.

nginx-tcp-lua-server's People

Contributors

membphis avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.