客户端CLIENTusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using RemoteObject;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;namespace CarClient
{
public partial class ClientForm : Form
{
public ClientForm()
{
InitializeComponent();
} RemoteObject.RemoteData rd;
private void btGet_Click(object sender, EventArgs e)
{
TcpClientChannel channel = new TcpClientChannel();
ChannelServices.RegisterChannel(channel,false);
RemotingConfiguration.RegisterWellKnownClientType(typeof(RemoteObject.RemoteData), "tcp://192.168.200.2:8086/hi");
rd = (RemoteObject.RemoteData)Activator.CreateInstance(typeof(RemoteObject.RemoteData));
rd_ErrorEvent();
}
private int rd_ErrorEvent()
{
int i=0;
DataSet ds = rd.GetData("select * from employee");
if (ds.Tables[0].Rows[0][1] .ToString()== "admin")
{
i= 1;
}
else
{
i= 0;
}
if (i == 1)
{
this.dgv.DataSource = rd.GetData("select * from employee").Tables[0].DefaultView;
}
else
{
MessageBox.Show("请输入正确的用户名和密码!");
}
return 1; }
}
}
服务器SERVERusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using RemoteObject;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;namespace CarTest
{
public partial class ServerForm : Form
{
public ServerForm()
{
CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
RemoteData rd=new RemoteData();
DataSet ds=rd.GetData("select * from employee");
this.dvg.DataSource = ds.Tables[0].DefaultView;
} private void ServerForm_Load(object sender, EventArgs e)
{
TcpServerChannel channel = new TcpServerChannel(8086);
ChannelServices.RegisterChannel(channel,false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject.RemoteData), "hi", WellKnownObjectMode.Singleton);
RemoteObject.RemoteData.SinkEvent+=new SinkHandle(RemoteData_SinkEvent);
}
private void RemoteData_SinkEvent(string fax)
{
this.tbServer.Text = fax;
}
}
}
问题:
在同一台机器上测试就可以
但是分别在两台机器上就出现了“System.Net.SocketException 由于目标机器积极拒绝,无法连接”提示
在客户端上用telnet 192.168.200.2 8086
能够正常登陆
服务端的防火墙也关闭了,系统自带的也关闭了,服务端一直开着~~~不知道出现了什么问题
晕啊~~~
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using RemoteObject;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;namespace CarClient
{
public partial class ClientForm : Form
{
public ClientForm()
{
InitializeComponent();
} RemoteObject.RemoteData rd;
private void btGet_Click(object sender, EventArgs e)
{
TcpClientChannel channel = new TcpClientChannel();
ChannelServices.RegisterChannel(channel,false);
RemotingConfiguration.RegisterWellKnownClientType(typeof(RemoteObject.RemoteData), "tcp://192.168.200.2:8086/hi");
rd = (RemoteObject.RemoteData)Activator.CreateInstance(typeof(RemoteObject.RemoteData));
rd_ErrorEvent();
}
private int rd_ErrorEvent()
{
int i=0;
DataSet ds = rd.GetData("select * from employee");
if (ds.Tables[0].Rows[0][1] .ToString()== "admin")
{
i= 1;
}
else
{
i= 0;
}
if (i == 1)
{
this.dgv.DataSource = rd.GetData("select * from employee").Tables[0].DefaultView;
}
else
{
MessageBox.Show("请输入正确的用户名和密码!");
}
return 1; }
}
}
服务器SERVERusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using RemoteObject;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;namespace CarTest
{
public partial class ServerForm : Form
{
public ServerForm()
{
CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
RemoteData rd=new RemoteData();
DataSet ds=rd.GetData("select * from employee");
this.dvg.DataSource = ds.Tables[0].DefaultView;
} private void ServerForm_Load(object sender, EventArgs e)
{
TcpServerChannel channel = new TcpServerChannel(8086);
ChannelServices.RegisterChannel(channel,false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject.RemoteData), "hi", WellKnownObjectMode.Singleton);
RemoteObject.RemoteData.SinkEvent+=new SinkHandle(RemoteData_SinkEvent);
}
private void RemoteData_SinkEvent(string fax)
{
this.tbServer.Text = fax;
}
}
}
问题:
在同一台机器上测试就可以
但是分别在两台机器上就出现了“System.Net.SocketException 由于目标机器积极拒绝,无法连接”提示
在客户端上用telnet 192.168.200.2 8086
能够正常登陆
服务端的防火墙也关闭了,系统自带的也关闭了,服务端一直开着~~~不知道出现了什么问题
晕啊~~~
在程序运行前和运行后端口没有任何异常
用netstat -a
可以看到端口正在侦听
你的代码看起来是没有问题的。
为什么啊?以下的地址就是上面的两个软件的地址:
http://www.cnblogs.com/Files/yeefa/CarTest.rar
http://www.cnblogs.com/Files/yeefa/s-clinet.rar
大家帮忙看看~~
tcp://192.168.200.2:8086/hi
把后面这个hi去掉怎么样?
客户端和服务端都改