Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<?php
$ctx = new \ZMQContext();
$rsock = $ctx->getSocket(\ZMQ::SOCKET_UPSTREAM);
$ssock = $ctx->getSocket(\ZMQ::SOCKET_PUB);
$rsock->connect('tcp://127.0.0.1:9997');
$ssock->connect('tcp://127.0.0.1:9996');
$ssock->setSockOpt(\ZMQ::SOCKOPT_IDENTITY, "70D107AB-19F5-44AE-A2D0-2326A167D8D7");
while (true) {
echo "WAITING FOR REQUEST...\n";
$str = $rsock->recv();
echo "RECEIVED\n";
list($sender,$conn_id,$path,$str) = explode(' ', $str, 4);
$res = sprintf(
"%s %d:%s, HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 3\r\n\r\nphp",
$sender,
strlen($conn_id),
$conn_id
);
$ssock->send($res);
echo "SEND: " . $res . "\n";
}
#!/usr/bin/env ruby
# coding: utf-8
require 'zmq'
con = ZMQ::Context.new
rsock = con.socket(ZMQ::UPSTREAM)
ssock = con.socket(ZMQ::PUB)
rsock.connect('tcp://127.0.0.1:9997')
ssock.connect('tcp://127.0.0.1:9996')
ssock.setsockopt(ZMQ::IDENTITY, "70D107AB-19F5-44AE-A2D0-2326A167D8D7")
loop do
puts "WAITING FOR REQUEST..."
str = rsock.recv
pust "RECEIVE";
sender, conn_id, path, str = str.split(' ', 4)
res = "#{sender} #{conn_id.size}:#{conn_id}, HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 4\r\n\r\nruby"
ssock.send res, 0
puts "SEND: #{res}"
end
# m2test.py
main = Server(
uuid ="2f62bd5-9e59-49cd-993c-3b6013c28f05",
chroot="./",
access_log="/logs/access.log",
error_log="/logs/error.log",
pid_file="/run/mongrel2.pid",
default_host="localhost",
name="main",
port=6767,
hosts=[
Host(
name="localhost",
routes={
'/m2test': Handler(
send_spec="tcp://127.0.0.1:9997",
send_ident="70D107AB-19F5-44AE-A2D0-2326A167D8D7",
recv_spec="tcp://127.0.0.1:9996",
recv_ident=""
)
}
)
]
)
settings = {"zeromq.threads": 1}
servers = [main]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment