Ok, following a simple example found I've got this:
Client:
RemoteClass:Code:namespace Remote { public partial class Client : Form { public Client() { InitializeComponent(); } private void Connectbutton_Click(object sender, EventArgs e) { TcpChannel chan = new TcpChannel(); System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(chan,true); RemoteClass oRemoteClass = (RemoteClass)Activator.GetObject(typeof(RemoteClass),"tcp://localhost:8025/Remote.RemoteClass"); DataSet ds = new DataSet(); ds = oRemoteClass.RunSql("SELECT * FROM persoane", "persoane"); dataGridView1.DataSource = ds.Tables["persoane"]; ChannelServices.UnregisterChannel(chan); } } }
and the Server:Code:using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.Sql; using System.Data.SqlClient; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; namespace Remote { class RemoteClass : MarshalByRefObject { private string _cs = "Data Source=(local);Initial Catalog=tickets;Integrated Security=True;"; public DataSet RunSql(string cSQL, string cTable) { SqlConnection _connection = new SqlConnection(_cs); SqlCommand _cmd = new SqlCommand(cSQL, _connection); SqlDataAdapter _adapter = new SqlDataAdapter(); DataSet _dataset = new DataSet(); try { _connection.Open(); _adapter.SelectCommand = _cmd; _adapter.Fill(_dataset, cTable); } catch (Exception exception) { throw new System.Exception(exception.Message); } if (_connection.State != ConnectionState.Closed) _connection.Close(); return _dataset; } } }
Code:namespace Remote { public partial class ListenerForm : Form { TcpChannel channel = new TcpChannel(8025); public ListenerForm() { InitializeComponent(); } private void Listenbutton_Click(object sender, EventArgs e) { System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel,true); RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteClass), "Remote.RemoteClass", WellKnownObjectMode.SingleCall); EventslistBox.Items.Add("http://localhost/Remote.RemoteClass:8025"); } } }
I was just wondering how can I make the updates to show on each client window.
In each client window there is a datagridview.
Also how can the server be informed of the clients connecting, leaving, making changes etc ?




Reply With Quote