因为在第三行
public UdpClient udpserver;
的时候,udpserver是一个类对象,将先调用
UdpClient udpserver = new UdpClient();
-------------------------------------
说的不对,
public UdpClient udpserver; // 这个只是声明,没有分配空间(实例化)UdpClient udpserver = new UdpClient(6000); // 是不是你装了防火墙了!!?

解决方案 »

  1.   

    to xz_king(西杀魄工人) 
    你说"public UdpClient udpserver; // 这个只是声明,没有分配空间(实例化)"
    不对吧?
    在c++里面,类成员将先调用自己的构造器啊.
    这个class很简单的,请你自己copy后运行下,如何?
    这和6000端口,以及防火墙无关的.
    错误说明:
    System.Net.Sockets.SocketException: 参考的对象种类不支持尝试的操作。
      

  2.   

    可能是 TCP 端口争用吧你试试
     public UdpClient udpserver = new UdpClient(6000);  
      

  3.   

    to "AhBian(阿扁)"
    public UdpClient udpserver = new UdpClient(6000);  
    当然没有问题了,这么作可以run啊
    class server
    {
     public UdpClient udpserver;
     public server(int port)
    {
    udpserver = new UdpClient(port);  //port=6000
    }
    }
    这么简单的class请大侠在你自己的机器上面run下看看吧
      

  4.   

    TO:  will38 (will38)  我试了一下,无论怎样做,我的机器上没有发现你所说的问题。即使用了 5999。不过我没测试继承的实现方式。