Code Monkey home page Code Monkey logo

multitcp's Introduction

###一个tcp的简单封装,这个是我们开发的分布式调度系统的通信组件,因为有更高性能的gevent的支持,所以这个组件算是废掉了。

###现在打算开源,基本是可以用,适合量级不是太大的环境。开发过程中,采用的一些模式还是有点意思的,有兴趣的朋友可以看看

###This is client

from multitcp import TCPClient
import threading

def go():
    print TCPClient().execute(cmd="hello_world",info='aini')
for i in range(10):
    t = threading.Thread(target=go)
    t.start()

###THis is server

from multitcp import TCPServer, TCPHandler
import time


class HelloWorldHandler(TCPHandler):
    def __init__(self, cmd=None, info=None):
        self.info = info
    def execute(self):
        print self.info
        time.sleep(5)
        return self.success(message=self.info)

if __name__ == "__main__":
    server = TCPServer()
    server.commands = {
        'hello_world': HelloWorldHandler
    }
    server.listen()

multitcp's People

Stargazers

 avatar chenbk avatar  avatar Shaozhi Zhang avatar  avatar DanielJia avatar

Watchers

fengyun.rui avatar  avatar  avatar

Forkers

chenbk85 ichem

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.