Sha256: 29c1e1ea35025aa69d1619b3f67b51da165cac0cd131a8008e837bb8293f4108
Contents?: true
Size: 699 Bytes
Versions: 2
Compression:
Stored size: 699 Bytes
Contents
# class QQ include QQAPI attr_reader :json def initialize(hostname: '0.0.0.0', port: 9455) @server = TCPServer.new(hostname, port) @event_method = [] end def bind(func) @event_method << func end def run loop do socket = @server.accept head socket socket.print "HTTP/1.1 204\r\nContent-Type: application/json\r\n\r\n" data = socket.gets @json = JSON.parse data @event_method.each { |func| func.call self } socket.close end end private def head(socket) puts 'head' while (line = socket.gets) != "\r\n" put line end puts 'end' end def put(text) print ' ' puts text end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
CQHTTP-0.2.0 | lib/CQHTTP/qq.rb |
CQHTTP-0.1.1 | lib/CQHTTP/qq.rb |