Coder Social home page Coder Social logo

socket-tentacles's Introduction

Socket tentacles

Simple thread based tcp client/server that divorces the concept of server/client from which side opens the tcp connection. Configured using a simple dictionary structure that can be easily read from json.

Example usage

import socket_tentacles

class ReceiveHandler(socket_tentacles.ReceiveHandler):
    def handle(self):
        for line in self.file:
            # Do something to line here

class SendHandler(socket_tentacles.SendHandler):
    def handle(self):
        while True:
            line = magic_global_send_queue.get()
            self.file.write(line)
            self.file.flush()

if __name__ == "__main__":
    with open(sys.argv[1]) as f:
        config = json.load(f)

    server = socket_tentacles.Server({"source": ReceiveHandler, "destination": SendHandler})
    server.configure(config)

Example config.json:

{
    "connections": [
        {"handler": "source", "type": "listen", "address": "tcp:1024"},
        {"handler": "destination", "type": "listen", "address": "tcp:1025"},
        {"handler": "destination", "type": "connect", "address": "tcp:localhost:1026"}
    ]
}

Note: configure() can be called multiple times. A later applied configuration overrides a previously applied one. However, already established tcp connections are not closed.

socket-tentacles's People

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.