C# .NET API

The C# .NET Server API allows .NET application to send real-time messages via the PushFYI WebSocket Gateway. The C# .NET API allow requests to be made synchronously as well as asynchronously.

C# .NET Server API has 7 main functions. In this documentation, we will examine the API usage and some of the best practices.

PushFYI - Interface Class

The PushFYI class is the entry point for any application to send receive real-time messages via the PushFYI WebSocket Gateway. This class wraps all the necessary methods to send real-time events.

This is not a singleton class and you can create more than one objects of this class.

Argument List:

SN parameters note
1 appsecret This parameter identifies your App when it connects to PushFYI. Since PushFYI can serve real-time messages to many apps simultaneously. This field allows PushFYI to distinguish between Apps, so that real-time messages from one App do not mix up with another App. The value of appsecret parameter is in UUID format. e.g. 123e4567-e89b-12d3-a456-426655440000
2 address URL of your pushfyi instance. e.g. http://10.0.0.101 for plain text connection and https://10.0.0.101 for secure connection.

Code Sample:


                                                      using libpushfyi;



    class Program
    {
        static void Main(string[] args)
        {
            /* 
 * initialize the connection 
 * @param app_secret
 * @param cluster_address
 */
            PushFYI p = new PushFYI("<your appsecret key>","https://<your pushfyi ip address>");
        }
    }
    

publish(channel, jsondata)

The publish method allows a .NET application to publish a real-time message as a json synchronously on a given data channel. PushFYI data channels are logical names to which real-time messages are sent to.

This method allows you to send messages as a json on a given data channel.

Parameter List:

SN parameters note
1 channel The logical name of the data channel associated with the event.
2 jsondata json string as template arguments.

Code Sample:

                                                      
                                                      using libpushfyi;
    class Program
    {
        static void Main(string[] args)
        {
            /* 
 * initialize the connection 
 * @param app_secret
 * @param cluster_address
 */
            PushFYI p = new PushFYI("<your appsecret key>","ws://<your pushfyi ip address>");
            /*
 * json with key and value for single channel
 */
            string jsondata= "{\"id\":\"emp01\",\"message\":{\"age\":\"30\",\"working\":{\"department\":\"IT\"}}}";
            /*
 * publish message synchronously on single channel in Realtime
 * @param user_data_channel
 * @param jsondata
 */
            p.publish("user_data_channel", jsondata);
        }
    }
    
                        

publish(channel, data)

The publish method allows a .NET application to publish a realtime message synchronously on a given data channel. PushFYI data channels are logical names to which realtime messages are sent to.

This method allows you to send messages as a Dictionary on a given data channel.

Parameter List:

SN parameters note
1 channel The logical name of the data channel associated with an event.
2 data Data type Dictionary with string as template argument.

Code Sample:

                                                      
                                                      using libpushfyi;
    class Program
    {
        static void Main(string[] args)
        {
            /* 
 * initialize the connection 
 * @param app_secret
 * @param cluster_address
 */
            PushFYI p = new PushFYI("<your appsecret key>","ws://<your pushfyi ip address>");
            /*
 * Dictionary with key and value for single channel
 */
            Dictionary<string,string>data = new Dictionary<string,string>();
            data.Add("name", "pushfyi");
            data.Add("msg", "Hello world");
            /*
 * publish message synchronously on single channel in Realtime
 * @param user_data_channel
 * @param data
 */
            p.publish("user_data_channel", data);
        }
    }
    
                        

publish(data)

The publish method allows a .NET application to publish a real-time message synchronously on a given multiple data channel. PushFYI data channels are logical names to which real-time messages are sent to.

This method allows you to send messages as a dictonary on multiple data channels.

Parameter List:

SN parameters note
1 dataset Data is in hashtable key value pair format where we can pass multiple channel and data in a dictonary format.

Code Sample:

                                                      
                                                      using libpushfyi;
    class Program
    {
        static void Main(string[] args)
        {
            /* 
 * initialize the connection 
 * @param app_secret
 * @param cluster_address
 */
            PushFYI p = new PushFYI("<your appsecret key>","ws://<your pushfyi ip address>");
            /*
 * Dictionary with key and value
 */
            Dictionary<string,string>data = new Dictionary<string,string>();

            data.Add("name", "pushfyi");
            data.Add("msg", "Hello world");

            /*
 * Dataset with key and value for multiple channel
 */
            Hashtable dataSet=new Hashtable();
            dataSet.Add("user_data_channel_1", data);
            dataSet.Add("user_data_channel_2", data);
            /*
 * publish message synchronously on multiple channel in Realtime
 * @param dataset
 */
            p.publish(dataset);
        }
    }
    
                        

publishAsync(channel, jsondata)

The publish method allows a .NET application to publish a real-time message as a json asynchronously on a given data channel. PushFYI data channels are logical names to which real-time messages are sent.

This method allows you to send messages as a json on a given data channel asynchronously.

Parameter List:

SN parameters note
1 channel The logical name of the data channel associated with an event.
2 jsondata json string as template argument.

Code Sample:

                                                      
                                                      using libpushfyi;
    class Program
    {
        static void Main(string[] args)
        {
            /* 
 * initialize the connection 
 * @param app_secret
 * @param cluster_address
 */
            PushFYI p = new PushFYI("<your appsecret key>","ws://<your pushfyi ip address>");
            /*
 * json with key and value for single channel
 */
            string jsondata= "{\"id\":\"emp01\",\"message\":{\"age\":\"30\",\"working\":{\"department\":\"IT\"}}}";
            /*
 * publish message asynchronously on single channel in Realtime
 * @param user_data_channel
 * @param jsondata
 */
            p.publishAsync("user_data_channel", jsondata);
        }
    }
    
                        

publishAsync(channel, data)

The publish method allows a .NET application to publish a real-time message asynchronously on a given data channel. PushFYI data channels are logical names to which real-time messages are sent.

This method allows you to send messages as a Dictionary on a given data channel asynchronously.

Parameter List:

SN parameters note
1 channel The logical name of the data channel associated with an event.
2 dictionary_data Data type Dictionary with string as template argument.

Code Sample:

                                                      
                                                      using libpushfyi;
    class Program
    {
        static void Main(string[] args)
        {
            /* 
 * initialize the connection 
 * @param app_secret
 * @param cluster_address
 */
            PushFYI p = new PushFYI("<your appsecret key>","ws://<your pushfyi ip address>");
            /*
 * Dictionary with key and value for single channel
 */
            Dictionary<string,string>data = new Dictionary<string,string>();
            data.Add("name", "pushfyi");
            data.Add("msg", "Hello world");
            /*
 * publish message asynchronously on single channel in Realtime
 * @param user_data_channel
 * @param data
 */
            p.publishAsync("user_data_channel", data);
        }
    }
    
                        

publishAsync(dataset)

The publish method allows a .NET application to publish a real-time message asynchronously on multiple data channels. PushFYI data channels are logical names to which real-time messages are sent.

This method allows you to send messages as a dictonary on multiple data channels.

Parameter List:

SN parameters note
1 dataset Data to be sent as a real-time messsage. Data which is in hashtable key value pair format where we can pass multiple channels and data in dictionary format.

Code Sample:

                                                      
                                                      using libpushfyi;
    class Program
    {
        static void Main(string[] args)
        {
            /* 
 * initialize the connection 
 * @param app_secret
 * @param cluster_address
 */
            PushFYI p = new PushFYI("<your appsecret key>","ws://<your pushfyi ip address>");
            /*
 * Dictionary with key and value
 */
            Dictionary<string,string>data = new Dictionary<string,string>();
            
            data.Add("name", "pushfyi");
            data.Add("msg", "Hello world");
            /*
 * Dataset with key and value for multiple channel
 */
            Hashtable dataSet=new Hashtable();
            dataSet.Add("user_data_channel_1", data);
            dataSet.Add("user_data_channel_2", data);
            /*
 * publish message asynchronously on multiple channel in Realtime
 * @param dataset
 */
            p.publishAsync(dataset);
        }
    }