Results 1 to 2 of 2
  1. #1
    Member
    Join Date
    Nov 2010
    Location
    HCMC
    Posts
    3

    Please help to fetch data to client

    Hi all
    I need to publish to webclient a message which is entered by user
    I have read some example (read much in Hello World, another example so complex to follow)
    I saw that in that sample, we create a server with Adapter set to an HelloWorldAdapter object
    Code:
     DataProviderServer server = new DataProviderServer();
     server.Adapter = new HelloWorldAdapter();
    And then when server.start() , it call Run() funtion to publish message "Hello World"
    According this example, I can only modify the message from HelloWorld to another, but I implement it as input from user
    Please show me another example to help or some way to finish my task

  2. #2
    Member
    Join Date
    Nov 2010
    Location
    HCMC
    Posts
    3
    Oh, I have it now
    just declare a public variable name message or property in HellowWorldAdapter
    In outside class, after start server, just assign this public this message and call HelloWorldAdapter. Run()
    It will automatically publish your message
    Following is my code:
    1.Code for Start server:
    Code:
            static DataProviderServer server;
            static TcpClient reqrepSocket;
            static TcpClient notifSocket;
            static HelloWorldAdapter adapter;
    
       private static void StartServer()
            {
                string host = "localhost";
                int reqrepPort = 6661;
                int notifPort = 6662;
    
                try
                {
                    adapter = new HelloWorldAdapter();
                    server = new DataProviderServer();
                    server.Adapter = adapter;
                    reqrepSocket = new TcpClient(host, reqrepPort);
                    server.RequestStream = reqrepSocket.GetStream();
                    server.ReplyStream = reqrepSocket.GetStream();
                    notifSocket = new TcpClient(host, notifPort);
                    server.NotifyStream = notifSocket.GetStream();
                    server.Start();
                    System.Console.WriteLine("Remote Adapter connected to Lightstreamer Server.");
                    System.Console.WriteLine("Ready to publish data...");
                }
                catch (Exception e)
                {
                    System.Console.WriteLine("Could not connect to Lightstreamer Server.");
                    System.Console.WriteLine("Make sure Lightstreamer Server is started before this Adapter.");
                    System.Console.WriteLine(e);
                }
            }
    When sending message, just call this and give message as parameter:
    Code:
    private static void SendToClient(string message)
            {
                adapter.instantMessage = message;
                adapter.Run();
            }
    And the rest is my HelloWorldAdapter:
    Code:
    using System;
    using System.Collections;
    using System.Threading;
    using Lightstreamer.Interfaces.Data;
    
    public class HelloWorldAdapter : IDataProvider
    {
        private IItemEventListener _listener;
        private volatile bool go;
        public string instantMessage = "";
        public void Init(IDictionary parameters, string configFile)
        {
        }
    
        public bool IsSnapshotAvailable(string itemName)
        {
            return false;
        }
    
        public void SetListener(IItemEventListener eventListener)
        {
            _listener = eventListener;
        }
    
        public void Subscribe(string itemName)
        {
            if (itemName.Equals("greetings"))
            {
                Thread t = new Thread(new ThreadStart(Run));
                t.Start();
            }
        }
    
        public void Unsubscribe(string itemName)
        {
            if (itemName.Equals("greetings"))
            {
                go = false;
            }
        }
    
        public void Run()
        {
            Random rand = new Random();
            IDictionary eventData = new Hashtable();
            eventData["message"] = instantMessage;
            _listener.Update("greetings", eventData, false);
            Thread.Sleep(1000 + rand.Next(2000));
        }
    }

 

 

Similar Threads

  1. Client receive old data after some time.
    By mnenchev in forum General
    Replies: 3
    Last Post: November 25th, 2009, 03:27 PM
  2. Error: Only a client can stream data.
    By lethanhclub in forum Adapter SDKs
    Replies: 6
    Last Post: September 16th, 2009, 11:26 AM
  3. Add dynamic data in Server and update it to Client
    By giangum in forum Client SDKs
    Replies: 1
    Last Post: September 1st, 2009, 10:20 AM
  4. data not coming to web client
    By rd2008 in forum Client SDKs
    Replies: 8
    Last Post: February 11th, 2009, 01:13 PM
  5. Web client not receiving any data?
    By TonyRoberts in forum Client SDKs
    Replies: 10
    Last Post: October 10th, 2007, 10:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT +1. The time now is 08:50 PM.