程序使用winform形式,分别放在不同的机器,一个服务器端,多个客户端。服务器端启动时会将数据读到内存,客户端要使用服务器端读到内存中的数据。请问:如何在客户端也能改变服务器端中内存中的数据?使用remoting....先谢了。
解决方案 »
- 请问,如何更改ListBox中项的顺序
- 【求助】怎么判断devexpress gridcontrol的数据被修改过
- 请教一个是否有结果的问题
- textbox内文字长度增加如何向左改变宽度!
- 散分贴:第一次在这里发帖却没有获得答案,郁闷的
- 请教Infragistics.WebUI.UltraWebGrid的两个问题
- 一个Windows Service在什么情况下会异常结束?
- web Service使用Timer组件定时执行的程序不停重入,打乱执行步骤,怎样解决?
- Enum.toString()的参数问题
- 子网掩码全0(0.0.0.0)和全1(255.255.255.255)分别代表什么意思?
- 老手看看!
- dropdownlist的选择值问题
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
namespace RemotingClass
{
public class FarClass
{
public static int i;
SqlConnection conn;
public FarClass()
{
conn = new SqlConnection();
conn.ConnectionString = "Data Source=localhost;Database=test;User ID=sa;Password=";
} public DataTable GetDataTable(string TableName)
{
SqlDataAdapter sda = new SqlDataAdapter("select * from " + TableName, conn);
DataSet ds = new DataSet();
sda.Fill(ds,TableName);
return ds.Tables[TableName];
}
}
}
remoting Server:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Services;
using System.Runtime.Remoting.Channels.Tcp;
using RemotingClass;
namespace RemotingServer
{
public partial class RemotingServerForm : Form
{
public RemotingServerForm()
{
InitializeComponent();
} private void RemotingServerForm_Load(object sender, EventArgs e)
{
TcpChannel chan = new TcpChannel(9999);
ChannelServices.RegisterChannel(chan);
FarClass fc = new FarClass();
ObjRef obj = RemotingServices.Marshal(fc, "Tcpservice");
RemotingServices.Unmarshal(obj);
//RemotingConfiguration.Configure("RemotingServer.exe.Config", false);
this.label1.Text = "服务端已启动";
}
}
}
Remoting Client:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Reflection;
using System.Diagnostics;
using RemotingClass;
using System.IO;
namespace RemotingClient
{
public partial class RemotingClientForm : Form
{
FarClass fc;
DataTable table;
public RemotingClientForm()
{
InitializeComponent();
} private void RemotingClientForm_Load(object sender, EventArgs e)
{
ChannelServices.RegisterChannel(new TcpChannel());
WellKnownClientTypeEntry RemotingConfing = new WellKnownClientTypeEntry(typeof(FarClass), "tcp:localhost:9999/TcpService");
RemotingConfiguration.RegisterWellKnownClientType(RemotingConfing);
//RemotingConfiguration.Configure("RemotingClient.exe.Config",false);
fc = new FarClass();
} private void button4_Click(object sender, EventArgs e)
{
table = new DataTable();
table = fc.GetDataTable("student");
this.dataGridView1.DataSource = table;
}
}
}