Socket
Book a DemoInstallSign in
Socket

unix_socks

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unix_socks

0.0.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

UnixSocks 🧦🧦

Description

A Ruby library for handling Unix socket-based communication.

Features

  • Message Handling: Simplify sending and receiving messages over Unix sockets.
  • Dynamic Method Access: Access message body values using method names (e.g., message.key).
  • Background Processing: Run the server in a background thread to avoid blocking main execution.
  • Robust Error Handling: Gracefully handle socket disconnections and JSON parsing errors.

Installation

Add this gem to your Gemfile:

gem 'unix_socks'

And install it using Bundler:

bundle install

Or install the gem directly:

gem install unix_socks

Usage

1. Server Setup

Create a server instance and start listening for connections:

require 'unix_socks'

server = UnixSocks::Server.new(socket_name: 'my_socket')

# Run the server in the background to avoid blocking
thread = server.receive_in_background(force: true) do |message|
  puts "Received message: #{message.inspect}"
end

thread.join

2. Sending Messages

Transmit messages to connected clients:

client = UnixSocks::Server.new(socket_name: 'my_socket')

# Prepare your message
message = { status: 'success', data: [1, 2, 3] }

# Send the message
client.transmit(message)

3. Responding to Messages

Handle incoming messages and send responses:

require 'unix_socks'

server = UnixSocks::Server.new(socket_name: 'my_socket')

def handle_message(message)
  # Access message body values using method names
  puts "Received status: #{message.status}"
  
  # Send a response
  message.respond({ status: 'acknowledged' })
end

# Use in your server setup
thread = server.receive_in_background(force: true) do |message|
  handle_message(message)
end

thread.join

And in the client:

client = UnixSocks::Server.new(socket_name: 'my_socket')

# Prepare your message
message = { status: 'success', data: [1, 2, 3] }

# Send the message
response = client.transmit_with_response(message)

# Receive the response
puts "Received server response status: #{response.status}"

4. Message Object Features

  • Dynamic Access: Methods like message.status automatically map to the message body.
  • Disconnect Handling: Safely close socket connections using disconnect.
  • Error Resilience: The respond method handles disconnections gracefully.

Author

Florian Frank

License

MIT License

FAQs

Package last updated on 13 Jul 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.