Socket
Socket
Sign inDemoInstall

simple-sock

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-sock

A Python library for simplified network and HTTP connections management.


Maintainers
1

simple-sock

simple-sock offers a straightforward interface for TCP and UDP sockets in Python, with support for optional SSL/TLS encryption and routing for TCP connections.

Basic Usage

Basic TCP Server

from simple_sock import Server

app = Server()

@app.tcp_listen()
def handle_tcp(data):
    print("Received:", data.msg)
    return "Response from TCP server"

app.run("localhost", 5454)  # Optional parameters: keyfile=None, certfile=None, timeout=0, buffer_size=1024

TCP Server with Routing

from simple_sock import Server

app = Server()

@app.parse_route
def parse_route(data):
    return data.msg.split()[0]

@app.tcp_listen()
def default_route(data):
    return "Default response"

@app.tcp_listen("route1")
def route1(data):
    return "Response for route1"

app.run("localhost", 5454)

Basic TCP Client

from simple_sock import Client

client = Client()
client.connect("localhost", 5454)  # Optional parameters: udp=False, tls=False
client.send("Hello from TCP client")
response = client.recv()
print(response)
client.close()

UDP Support

UDP usage is similar; use @app.udp_listen() for servers and set udp=True for clients. Example:

# UDP Server
app = Server(udp=True)
@app.udp_listen()
def handle_udp(data):
    print("Received:", data.msg)
    return "Response from UDP server"
app.run("localhost", 5455")

# UDP Client
client.connect("localhost", 5455, udp=True)
client.send("Hello from UDP client")
response, addr = client.recv()
print(response)
client.close()

License

MIT License

Contact

For questions, contact Leonardo Oliveira at email.

Keywords

FAQs


Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc