/
PublishExample.aspx.cs
72 lines (62 loc) · 2.4 KB
/
PublishExample.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json.Linq;
using System.Diagnostics;
namespace csharp_webApp
{
public partial class PublishExample : System.Web.UI.Page
{
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] + "]");
}
}
}