Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Please note that this branch is just temporary module of sock module. If the pull request is merged, this branch will be removed.
Small script to simplify network communication.
Something like telnetlib, but for clean TCP/UDP (no command sequences, \r\n newlines, etc.)
As an alternative, consider pwntools which contains unified interface (tubes) for communications with sockets, processes, etc. See tubes API.
Current development only supports python 3. Old python 2 version is available at the py2 branch.
$ pip3 install sock-websocket
For development or building from this repository, poetry is needed.
from sock import *
f = Sock("some.cool.servi.ce:3123", timeout=10)
# or IPv6
f = Sock6("::1 3123", timeout=3)
# or already existing socket
f = Sock.from_socket(some_socket) # or toSock(some_socket)
# or UDP/IPv6
f = SockU6("::1 3123", timeout=3)
# or WebSocket
# For using WebSock, the websocket-client module must be installed (pip install websocket-client).
f = WebSock("ws://localhost:3123")
# 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
result1 = f.skip_until_re(r"You've got (heads|tails)") # skip_until(str) also exists
# read until also consumes matched part
f.read_until_re(r"You've g[oe]t ") # read_until(str) also exists
# read specific number of bytes
result2 = f.read_nbytes(5)
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())
Author: hellman
License: MIT License
FAQs
Small script to simplify network communication
We found that sock-websocket demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.