Giter Site home page Giter Site logo

epoll's Introduction

Epoll

Event-based socket server, which uses epoll

        EpollServer server = new EpollServer(8080) {
            @Override
            protected IOThread createIOThread() {
                return new IOThread() {
                    byte[] buffer = new byte[1024];
                    byte[] data = ("HTTP/1.1 200 OK\r\n" +
                            "Connection: Keep-Alive\r\n" +
                            "Content-Length: 11\r\n" +
                            "Content-Type: text/html;charset=UTF-8\r\n" +
                            "\r\n" +
                            "it's alive!").getBytes();

                    @Override
                    public void onConnect(Connection connection) {
                        System.out.println("new connection!");
                    }

                    @Override
                    public void onDisconnect(Connection connection) {
                        System.out.println("we lost him =(");
                    }

                    @Override
                    public void onRead(Connection connection) {
                        try {
                            int r = connection.read(buffer, 0, buffer.length);
                            System.out.println("request: " + new String(buffer, 0, r));
                            connection.write(data);
                        } catch (IOException e) {
                            connection.close();
                        }
                    }
                };
            }
        };
        server.setIoThreadsCount(4);
        server.start();

Notes

to build you will need to install libssl-dev

to build 32x version on 64x OS you will need to install libc6-dev-i386 libssl-dev:i386

Download

bintray

epoll's People

Contributors

wizzardo avatar leoge0113 avatar

Watchers

James Cloos 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.