Skip to content
This repository was archived by the owner on May 2, 2026. It is now read-only.
foiPublic archive

About

JSON-socket client & server implementation. Inspired by and compatible with sebastianseilund/node-json-socket

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

32 Commits

Folders and files

Repository files navigation

ruby json-socket .github/workflows/ci.yml

JSON-socket client & server implementation based on async-io. Inspired by and compatible with sebastianseilund/node-json-socket and crystal json-socket

Oj is used for encoding/parsing json.

Installation

gem install json-socket

or in Bundler

gem 'json-socket'

Usage

server.rb

require "json-socket"

class CustomJSONSocketServer < JSONSocket::Server

  def on_message(message, client)
    puts message
    result = message["a"] + message["b"]
    self.send_end_message({ :result => result }, client)
  end

  def on_error e
    STDERR.puts "Error: #{e.message}"
  end
end

server = CustomJSONSocketServer.new(host: "localhost", port: 1234, delimeter: "ц") # OR via unix socket CustomJSONSocketServer.new(unix_socket: "/tmp/s.sock", delimeter: "ц")
server.listen

client.rb

require "json-socket"

to_server = JSONSocket::Client.new(host: "localhost", port: 1234, delimeter: "ц") # OR via unix socket CustomJSONSocketServer.new(unix_socket: "/tmp/s.sock", delimeter: "ц")

10.times do |i|
  result = to_server.send({ "a" => i, "b" => i + 10 })
  p result
end

About

JSON-socket client & server implementation. Inspired by and compatible with sebastianseilund/node-json-socket

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages