Created
September 18, 2010 07:29
-
-
Save faultier/585455 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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