客户端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
能够正常登陆
服务端的防火墙也关闭了,系统自带的也关闭了,服务端一直开着~~~不知道出现了什么问题
晕啊~~~

解决方案 »

  1.   

    在客户机上用netstat -a
    在程序运行前和运行后端口没有任何异常
      

  2.   

    但是为什么同一台机又可以呢
    用netstat -a
    可以看到端口正在侦听
      

  3.   

    前一阵CSDN也出现过同样的问题。
      

  4.   

    你先用remoting object 建一个简单的服务器和一个客户端测试一下。
    你的代码看起来是没有问题的。
      

  5.   

    我又重新做过一个最简单C/S程序,结果还是那样子
    为什么啊?以下的地址就是上面的两个软件的地址:
    http://www.cnblogs.com/Files/yeefa/CarTest.rar
    http://www.cnblogs.com/Files/yeefa/s-clinet.rar
    大家帮忙看看~~
      

  6.   

    这个错误很正常楼主应该把服务端(windows服务)先开启然后运行客户端就没有问题了
      

  7.   

    TCP穿透NAT和防火墙的特点与测评.pdf
      

  8.   

    从现象上看是服务端没有启动原因可能是服务端没有监听8086端口,或者客户端8086端口无法与外面通讯 
    tcp://192.168.200.2:8086/hi
    把后面这个hi去掉怎么样?
      

  9.   

    改成 hi.soap试一下
    客户端和服务端都改