Skip to content

Instantly share code, notes, and snippets.

@badboy
Created March 11, 2010 15:28
Show Gist options
  • Save badboy/329237 to your computer and use it in GitHub Desktop.
Save badboy/329237 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# encoding: utf-8
require 'socket'
require 'json'
require 'pp'
I3_SOCKET_PATH = "/tmp/i3-ipc.sock"
message = "i3-ipc" + [0,1].pack("LL")
socket = UNIXSocket.new(I3_SOCKET_PATH)
len = socket.write(message)
buffer = socket.read(len)
abort('wrong answer') unless buffer[0, "i3-ipc".length]
len, type = buffer[6..-1].unpack("LL")
abort('wrong type returned') unless type == 1
ws = socket.read(len)
js_ws = JSON.parse(ws)
pp js_ws
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment