Code Monkey home page Code Monkey logo

sock's Introduction

sock

Small script to simplify network communication. Something like telnetlib http://docs.python.org/library/telnetlib.html, but for clean TCP/UDP (no command sequences, \r\n newlines, etc.)

Usage

###TCP Client

from sock import *

f = Sock("some.cool.servi.ce:3123", timeout=10, log_send=False, log_recv=True)
# or IPv6
f = Sock6("::1 3123", timeout=3)
# or already existing socket
f = toSock(some_socket)

# wait for prompt (skip banner for example)
# the prompt itself will be skipped (and returned) too
f.read_until("> ", timeout=3)  # read_until_re also exists

f.send("flip coin\n")

# skip until regexp
match = f.skip_until_re(r"You've got (heads|tails)")    # skip_until also exists
result1 = match.group(1)

# read specific number of bytes
result2 = f.read_nbytes(11+5)[11:16]

assert result1 == result2

# alias for f.send(s + "\n")
f.send_line("random please")

# read one packet and flush buffers
print f.read_one()

# non-blocking read (flush buffers)
print f.read_one(0)

# read until disconnect
print f.read_all()

About

This software uses Semantic Versioning ( http://semver.org/ )

Author: hellman ( [email protected] ) Fork: dkohlbre ([email protected])

License: MIT License (http://opensource.org/licenses/MIT)

sock's People

Contributors

hellman avatar dkohlbre avatar nolze avatar

Watchers

 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.