i send a data with
curl -s -v -X POST '
http://89.107.225.193:8000/pub?id=test' -d 'hello'
{"channel": "test", "published_messages": "2", "stored_messages": "2",
"subscribers": "0"}
here is my nginx conf
=================================================
push_stream_shared_memory_size 500m;
push_stream_max_channel_id_length 200;
# max messages to store in memory
push_stream_max_messages_stored_per_channel 50;
# message ttl
push_stream_message_ttl 5m;
# ping frequency
push_stream_ping_message_interval 10s;
# connection ttl to enable recycle
push_stream_subscriber_connection_ttl 15m;
# connection ttl for long polling
push_stream_longpolling_connection_ttl 30s;
# broadcast
push_stream_broadcast_channel_prefix "broad_";
#push_stream_message_template "{\"id\":~id~,
\"channel\":\"~channel~\",\"text\":\"~text~\",\"eventid\":\"~event-id~
\"}";
push_stream_message_template "{\"id\":~id~,\"channel
\":\"~channel~\",\"text\":\"~text~\"}";
# subscriber may create channels on demand or only authorized
# (publisher) may do it?
push_stream_authorized_channels_only off;
push_stream_broadcast_channel_max_qtd 3;
server {
listen 8000 default_server;
#listen 9443 ssl;
#ssl_certificate /usr/local/nginx/ssl/server.crt;
#ssl_certificate_key /usr/local/nginx/ssl/server.key;
server_name 192.168.200.193;
location /channels-stats {
# activate channels statistics mode for this location
push_stream_channels_statistics;
# query string based channel id
set $push_stream_channel_id $arg_id;
}
location /pub {
# allow workstation
allow 192.168.200.200;
# drop rest of the world
deny all;
# activate publisher mode for this location, with admin
support
push_stream_publisher admin;
# query string based channel id
set $push_stream_channel_id $arg_id;
# store messages in memory
push_stream_store_messages on;
# Message size limit
# client_max_body_size MUST be equal to
client_body_buffer_size or
# you will be sorry.
client_max_body_size 32k;
client_body_buffer_size 32k;
}
location ~ /sub/(.*) {
# activate subscriber mode for this location
push_stream_subscriber;
# positional channel path
set $push_stream_channels_path $1;
# header to be sent when receiving new subscriber
connection
push_stream_header_template
"<html><head><meta http-equiv=\"Content-Type\" content=\"text/html;
charset=utf-8\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-
store\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\r
\n<meta http-equiv=\"Pragma\" content=\"no-cache\">\r\n<meta http-
equiv=\"Expires\" content=\"Thu, 1 Jan 1970 00:00:00 GMT\">\r\n<script
type=\"text/javascript\">\r\nwindow.onError = null;\r
\ntry{ document.domain = (window.location.hostname.match(/^(\d{1,3}\.)
{3}\d{1,3}$/)) ? window.location.hostname :
window.location.hostname.split('.').slice(-2).join('.');}catch(e){}\r
\nparent.PushStream.register(this);\r\n</script>\r\n</head>\r
\n<body>";
# message template
#push_stream_message_template
"<script>p(~id~,'~channel~','~text~','~event-id~');</script>";
push_stream_message_template
"<script>p(~id~,'~channel~','~text~');</script>";
# footer to be sent when finishing subscriber connection
push_stream_footer_template "</body></
html>";
# content-type
push_stream_content_type "text/html;
charset=utf-8";
}
location ~ /ev/(.*) {
# activate subscriber mode for this location
push_stream_subscriber;
# activate event source support for this location
push_stream_eventsource_support on;
# positional channel path
set $push_stream_channels_path $1;
# message template
push_stream_message_template "{\"id\":~id~,
\"channel\":\"~channel~\",\"text\":\"~text~\"}";
# ping frequency
push_stream_ping_message_interval 10s;
}
location ~ /lp/(.*) {
# activate long-polling mode for this location
push_stream_subscriber long-polling;
# positional channel path
set $push_stream_channels_path $1;
# message template
push_stream_message_template "'{\"id\":~id~,
\"channel\":\"~channel~\",\"text\":\"~text~\",\"tag\":~tag~,\"time\":
\"~time~\"}'";
push_stream_last_received_message_tag $arg_tag;
push_stream_last_received_message_time $arg_time;
# connection timeout
push_stream_longpolling_connection_ttl 30s;
}
location ~ /ws/(.*) {
# activate websocket mode for this location
push_stream_websocket;
# positional channel path
set $push_stream_channels_path $1;
# message template
push_stream_message_template "{\"id\":~id~,
\"channel\":\"~channel~\",\"text\":\"~text~\"}";
# store messages in memory
push_stream_store_messages on;
push_stream_websocket_allow_publish on;
# ping frequency
push_stream_ping_message_interval 10s;
}
}
here is my code
==============================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"
http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;
charset=utf-8" />
<title>Long Polling Example</title>
</head>
<body>
<p>Messages:</p>
<div id="messages" style="width:800px;height:
300px;overflow:scroll;"></div>
<script src="/js/pushstream.js" type="text/javascript"
language="javascript" charset="utf-8"></script>
<script type="text/javascript" language="javascript"
charset="utf-8">
// <![CDATA[
function messageReceived(text, id, channel) {
document.getElementById('messages').innerHTML += id + ': ' +
text + '<br>';
};
var pushstream = new PushStream({
host: 89.107.225.193,
port: 8000,
modes: "longpolling",
});
pushstream.onmessage = messageReceived;
pushstream.addChannel('test');
pushstream.connect();
// ]]>
</script>
</body>
</html>