protected void Page_Load(object sender, EventArgs e) { // channel name string channel = "test-iis"; // Initialize pubnub state pubnub objPubnub = new pubnub( "demo", // PUBLISH_KEY "demo", // SUBSCRIBE_KEY "demo", // SECRET_KEY "demo", // CIPHER_KEY false // SSL_ON? ); List <object> info = null; Dictionary <string, object> args = new Dictionary <string, object>(); // Publish string message args.Add("channel", channel); args.Add("message", "Hello Csharp - IIS"); info = objPubnub.Publish(args); // Print Response Debug.WriteLine(" ");; Debug.WriteLine("Published messages - >"); Debug.WriteLine("[ " + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]"); // Publish message in array format args = new Dictionary <string, object>(); JArray jarr = new JArray(); jarr.Add("Sunday"); jarr.Add("Monday"); jarr.Add("Tuesday"); jarr.Add("Wednesday"); jarr.Add("Thursday"); jarr.Add("Friday"); jarr.Add("Saturday"); args.Add("channel", channel); args.Add("message", jarr); info = objPubnub.Publish(args); // Print Response Debug.WriteLine("[ " + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]"); // Publish message in object(key - val) format args = new Dictionary <string, object>(); JObject jObj = new JObject(); jObj.Add("Name", "John"); jObj.Add("age", "25"); args.Add("channel", channel); args.Add("message", jObj); info = objPubnub.Publish(args); // Print Response Debug.WriteLine("[" + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]"); }
protected void Page_Load(object sender, EventArgs e) { // channel name string channel = "test-iis"; // Initialize pubnub state pubnub objPubnub = new pubnub( "demo", // PUBLISH_KEY "demo", // SUBSCRIBE_KEY "demo", // SECRET_KEY "", // CIPHER_KEY (Cipher key is Optional) false // SSL_ON? ); List<object> info = null; Dictionary<string, object> args = new Dictionary<string, object>(); // Publish string message args.Add("channel", channel); args.Add("message", "Hello Csharp - IIS"); info = objPubnub.Publish(args); // Print Response Debug.WriteLine(" "); ; Debug.WriteLine("Published messages - >"); Debug.WriteLine("[ " + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]"); // Publish message in array format args = new Dictionary<string, object>(); JArray jarr = new JArray(); jarr.Add("Sunday"); jarr.Add("Monday"); jarr.Add("Tuesday"); jarr.Add("Wednesday"); jarr.Add("Thursday"); jarr.Add("Friday"); jarr.Add("Saturday"); args.Add("channel", channel); args.Add("message", jarr); info = objPubnub.Publish(args); // Print Response Debug.WriteLine("[ " + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]"); // Publish message in object(key - val) format args = new Dictionary<string, object>(); JObject jObj = new JObject(); jObj.Add("Name", "John"); jObj.Add("age", "25"); args.Add("channel", channel); args.Add("message", jObj); info = objPubnub.Publish(args); // Print Response Debug.WriteLine("[" + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]"); }
public static void publishAndSetStatus(string channel, object message) { // Publish message in array format Dictionary <string, object> args = new Dictionary <string, object>(2); args.Add("channel", channel); args.Add("message", message); // publish Response List <object> info = _pubnub.Publish(args); int sent = Convert.ToInt32(status["sent"]); status.Remove("sent"); status.Add("sent", sent + 1); test(info != null, "publish complete"); test(info != null && info.Count > 2, "publish responce"); if (info == null || info.Count <= 0) { delivery_retries += 1; if (max_retries > delivery_retries) { publishAndSetStatus(channel, message); } } }
protected void btnPublish_Click(object sender, EventArgs e) { List <object> info = null; Dictionary <string, object> args = new Dictionary <string, object>(); // Publish string message args.Add("channel", channel); args.Add("message", "Hello Csharp - IIS"); info = objPubnub.Publish(args); // Print response System.Diagnostics.Debug.WriteLine(""); System.Diagnostics.Debug.WriteLine("Published messages - >"); System.Diagnostics.Debug.WriteLine("[ " + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]"); // Publish message in array format JArray jarr = new JArray(); jarr.Add("Sunday"); jarr.Add("Monday"); jarr.Add("Tuesday"); jarr.Add("Wednesday"); jarr.Add("Thursday"); jarr.Add("Friday"); jarr.Add("Saturday"); args = new Dictionary <string, object>(); args.Add("channel", channel); args.Add("message", jarr); info = objPubnub.Publish(args); // Print response System.Diagnostics.Debug.WriteLine("[ " + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]"); // Publish message in object(key - val) format JObject jObj = new JObject(); jObj.Add("Name", "John"); jObj.Add("age", "25"); args = new Dictionary <string, object>(); args.Add("channel", channel); args.Add("message", jObj); info = objPubnub.Publish(args); // Print response System.Diagnostics.Debug.WriteLine("[" + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]"); Response.Write("See the output at the time of debugging in output window"); }
static public void test_publish() { // Initialize pubnub state pubnub objPubnub = new pubnub( "demo", // PUBLISH_KEY "demo", // SUBSCRIBE_KEY "demo", // SECRET_KEY "", // CIPHER_KEY (Cipher key is Optional) false // SSL_ON? ); //define channel string channel = "hello-world"; List <object> info = null; Dictionary <string, object> args = new Dictionary <string, object>(); // Publish string message args.Add("channel", channel); args.Add("message", "Hello Csharp - IIS"); info = objPubnub.Publish(args); // Print response Debug.WriteLine(""); Debug.WriteLine("Published messages - >"); if (info != null) { if (info.Count == 3) { Debug.WriteLine("[" + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]"); } else if (info.Count == 2) { Debug.WriteLine("[" + info[0].ToString() + ", " + info[1] + "]"); } } else { Debug.WriteLine("Error in network connection"); } }
protected void Page_Load(object sender, EventArgs e) { // channel name string channel = "test-iis"; pubnub objPubnub = new pubnub( "demo", // PUBLISH_KEY "demo", // SUBSCRIBE_KEY "demo", // SECRET_KEY "", // CIPHER_KEY (Cipher key is Optional) false // SSL_ON? ); pubnub.Procedure Receiver = delegate(object message) { Debug.WriteLine(message); Dictionary <string, object> arg = new Dictionary <string, object>(); arg.Add("channel", channel); //Unsubscribe messages objPubnub.Unsubscribe(arg); return(true); }; pubnub.Procedure ConnectCallback = delegate(object message) { Debug.WriteLine(message); // Publish String Message Dictionary <string, object> publish = new Dictionary <string, object>(); publish.Add("channel", channel); publish.Add("message", "Hello World!!!!"); // publish Response objPubnub.Publish(publish); return(true); }; pubnub.Procedure DisconnectCallback = delegate(object message) { Debug.WriteLine(message); return(true); }; pubnub.Procedure ReconnectCallback = delegate(object message) { Debug.WriteLine(message); return(true); }; pubnub.Procedure ErrorCallback = delegate(object message) { Debug.WriteLine(message); return(true); }; Dictionary <string, object> args = new Dictionary <string, object>(); args.Add("channel", channel); args.Add("callback", Receiver); // callback to get response args.Add("connect_cb", ConnectCallback); // callback to get connect event args.Add("disconnect_cb", DisconnectCallback); // callback to get disconnect event args.Add("reconnect_cb", ReconnectCallback); // callback to get reconnect event args.Add("error_cb", ErrorCallback); // callback to get error event // Subscribe messages objPubnub.Subscribe(args); }
public static void test_publish() { // Initialize pubnub state pubnub objPubnub = new pubnub( "demo", // PUBLISH_KEY "demo", // SUBSCRIBE_KEY "demo", // SECRET_KEY "", // CIPHER_KEY (Cipher key is Optional) false // SSL_ON? ); //define channel string channel = "hello-world"; List<object> info = null; Dictionary<string, object> args = new Dictionary<string, object>(); // Publish string message args.Add("channel", channel); args.Add("message", "Hello Csharp - IIS"); info = objPubnub.Publish(args); // Print response Debug.WriteLine(""); Debug.WriteLine("Published messages - >"); if (info != null) { if (info.Count == 3) { Debug.WriteLine("[" + info[0].ToString() + ", " + info[1] + ", " + info[2] + "]"); } else if (info.Count == 2) { Debug.WriteLine("[" + info[0].ToString() + ", " + info[1] + "]"); } } else { Debug.WriteLine("Error in network connection"); } }
protected void Page_Load(object sender, EventArgs e) { // channel name string channel = "test-iis"; pubnub objPubnub = new pubnub( "demo", // PUBLISH_KEY "demo", // SUBSCRIBE_KEY "demo", // SECRET_KEY "", // CIPHER_KEY (Cipher key is Optional) false // SSL_ON? ); pubnub.Procedure Receiver = delegate(object message) { Debug.WriteLine(message); Dictionary<string, object> arg = new Dictionary<string, object>(); arg.Add("channel", channel); //Unsubscribe messages objPubnub.Unsubscribe(arg); return true; }; pubnub.Procedure ConnectCallback = delegate(object message) { Debug.WriteLine(message); // Publish String Message Dictionary<string, object> publish = new Dictionary<string, object>(); publish.Add("channel", channel); publish.Add("message", "Hello World!!!!"); // publish Response objPubnub.Publish(publish); return true; }; pubnub.Procedure DisconnectCallback = delegate(object message) { Debug.WriteLine(message); return true; }; pubnub.Procedure ReconnectCallback = delegate(object message) { Debug.WriteLine(message); return true; }; pubnub.Procedure ErrorCallback = delegate(object message) { Debug.WriteLine(message); return true; }; Dictionary<string, object> args = new Dictionary<string, object>(); args.Add("channel", channel); args.Add("callback", Receiver); // callback to get response args.Add("connect_cb", ConnectCallback); // callback to get connect event args.Add("disconnect_cb", DisconnectCallback); // callback to get disconnect event args.Add("reconnect_cb", ReconnectCallback); // callback to get reconnect event args.Add("error_cb", ErrorCallback); // callback to get error event // Subscribe messages objPubnub.Subscribe(args); }