i have modified the code and executed, when i run the application from visual studio its properly without any errors. this is the flow of my code 1st my dataadapter constructor execute
server.Start()method will execute in the
DataAdapterLauncher class next init() method from MyDataAdapter class is called there i opened the connection and next its executes
SetListener() method after that it execute console.Writeline method next to
server.Start() method will be called, this is the i wrote for testing check.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lightstreamer.Interfaces.Data;
using System.Collections;
using System.Data;
using System.Threading;
using System.Data.SqlClient;
namespace DataAdapterDemo
{
public class MyDataAdapter : IDataProvider, IExternalFeedListener
{
private IItemEventListener listener;
private volatile bool go;
private DataTable dt;
public SqlConnection conn;
private SqlCommand comm;
private IDictionary subscribedItems;
public MyDataAdapter()
{
//dt = new DataTable();
//subscribedItems = new Hashtable();
}
public void Init(IDictionary parameters, string configFile)
{
try
{
conn = new SqlConnection("Data Source=(local);Database=Northwind; Integrated Security=true;");
comm = new SqlCommand("Select * from Orders", conn);
conn.Open();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex);
throw new DataProviderException(ex.Message.ToString());
}
}
public void SetListener(IItemEventListener eventListener)
{
listener = eventListener;
}
public void Subscribe(string itemName)
{
if (itemName.Equals("item"))
{
Thread t = new Thread(new ThreadStart(Run));
t.Start();
}
}
public void Unsubscribe(string itemName)
{
if (itemName.Equals("item"))
{
go = false;
}
}
public bool IsSnapshotAvailable(string itemName)
{
if (!itemName.StartsWith("item"))
throw new SubscriptionException("Unexpected item: " + itemName);
return true;
}
public void Run()
{
go = true;
try
{
while (go)
{
SqlDataReader dr = comm.ExecuteReader();
while (dr.Read())
{
IDictionary eventData = new Hashtable();
eventData.Add("OrderID", dr[0]);
eventData.Add("UnitPrice", dr[1]);
eventData.Add("Quantity", dr[2]);
eventData.Add("Discount", dr[3]);
listener.Update("item", eventData, false);
}
}
}
catch (Exception ex) { Console.WriteLine(ex); }
try { Thread.Sleep(1000); }
catch (ThreadInterruptedException ex) { Console.WriteLine(ex); }
finally { conn.Close(); }
}
public void onEvent(string itemName, IDictionary currentValues, bool isSnapshot)
{
lock (subscribedItems)
{
if (!subscribedItems.Contains(itemName)) return;
bool started = (bool)subscribedItems[itemName];
if (!started)
{
if (!isSnapshot)
return;
subscribedItems[itemName] = true;
}
else
{
if (isSnapshot)
{
isSnapshot = false;
}
}
}
if (listener != null)
listener.Update(itemName, currentValues, isSnapshot);
}
}
}
public interface IExternalFeedListener
{
void onEvent(string itemName, IDictionary currentValues, bool isSnapshot);
}
DataAdapterLauncher.cs code
public class DataAdapterLauncher
{
public static void Main(string[] args)
{
string host = ConfigurationManager.AppSettings[0].ToString();
int reqRepPort = Convert.ToInt32(ConfigurationManager.AppSettings[1].ToString());
int notifPort = Convert.ToInt32(ConfigurationManager.AppSettings[2].ToString());
try
{
DataProviderServer server = new DataProviderServer();
server.Adapter = new MyDataAdapter();
TcpClient reqrepSocket = new TcpClient(host,reqRepPort);
server.RequestStream = reqrepSocket.GetStream();
server.ReplyStream = reqrepSocket.GetStream();
TcpClient notifSocket = new TcpClient(host, notifPort);
server.NotifyStream = notifSocket.GetStream();
server.Start();
Console.WriteLine("Remote Adapter connected to LightStreamer Server...");
Console.WriteLine("Ready to publish data...");
}
catch (Exception ex)
{
Console.WriteLine("Could not connect to Lightstreamer Server.");
Console.WriteLine("Make sure Lightstreamer Server is started before this Adapter.");
Console.WriteLine(ex);
}
}
}
when i call client code then i get the "UNABLE TO CONNECT" message