CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Threaded View

  1. #9
    Join Date
    Dec 2008
    Location
    Romania
    Posts
    28

    Re: Work with real-time data

    Ok, following a simple example found I've got this:

    Client:
    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);
            }
        }
    }
    RemoteClass:

    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;
            }
    
        }
    }
    and the Server:
    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 ?
    Last edited by arhicoc; January 15th, 2009 at 11:33 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured