类似下边这种语句我不知道你在什么地方看来的
IPEndPoint dummy = null; 
byte[] res = qClient.client.Receive ( ref dummy ); 
result = System.Text.Encoding.ASCII.GetString(res); 我查找.net帮助信息好像和你的使用方法很大不同从绑定的 Socket 套接字接收数据,将数据存入接收缓冲区。 命名空间:System.Net.Sockets
程序集:System(在 system.dll 中)public int Receive (
byte[] buffer
)public static int SendReceiveTest1(Socket server)
{
    byte[] msg = Encoding.UTF8.GetBytes("This is a test");
    byte[] bytes = new byte[256];
    try 
    {
        // Blocks until send returns.
        int i = server.Send(msg);
        Console.WriteLine("Sent {0} bytes.", i);
        
        // Get reply from the server.
        i = server.Receive(bytes);
        Console.WriteLine(Encoding.UTF8.GetString(bytes));
    }
    catch (SocketException e)
    {
        Console.WriteLine("{0} Error code: {1}.", e.Message, e.ErrorCode);
        return (e.ErrorCode);
    }
    return 0;
}你的Receive的参数与返回值太让人疑惑了。

解决方案 »

  1.   

    你看看这。。
            public void Send()
            {
                try{
                tcp=new TcpClient ("127.0.0.1",51888);
                tcp.Connect("127.0.0.1",51888);
                networkstream =tcp.GetStream ();
                byte []bt= System .Text .Encoding .Default .GetBytes(Sendtext );
                        networkstream .Write (bt,0,bt.Length );
                       networkstream .Flush ();
                        networkstream .Close ();
                }
                catch (SocketException e)
                {errstring=e.Message ;
                    return ;
                }
             
            }        public void StartListen()
            {
                Thread startlistenthread = new Thread(new ThreadStart(listenPort));
               
            }
            void ListenPort()
            {
                listen.Start();
                while (true)
                {tcp =null;
                    try
                    {
                        tcp=listen .AcceptTcpClient();                                                  }
                    catch (SocketException e)
                    {
                        this.errstring =e.Message ;
                        return ;
                    }
                    ///////////////////////接收数据
                   Thread receive=new Thread (new ThreadStart (Receive));
                   riceive.Start();
                    ///////////////////////////////
                }
                       }
            public void CloseListen()
            {
                throw new System.NotImplementedException();
                if(listen!=null)
                {listen =null ;}
            }        public void Receive()
            {
                 networkstream =tcp.GetStream();
                    while (true)
                    {
                       byte []bt=new byte [1024];
                        networkstream .Read (bt,0,bt.Length );
                        recevietext =System .Text .Encoding.Default .GetString (bt);
                        networkstream .Close ();                }
               
            }
      

  2.   

    调试服务端程序,看看是哪里出错,你可以将程序代码用try... catch...包围,打印错误信息log到文件中看看是什么错误。