1.各位大侠能否告诉在下如何让线程(THREAD)重复使用,不能用NEW来重新建立而是直接执行第二个方法(不是用线程池)?
2.TCPCLIENT在循环发送数据给服务器,能否只实例一次,调用第一次实例的对象发送数据?

解决方案 »

  1.   

    谢谢如梦。。那TCPCLIENT能否重用?,每次使用都要重新实例然后连接,好像不怎么舒服
      

  2.   

    这样的发送过程可以多次的!
    TcpClient client = new TcpClient(server, port);    // Translate the passed message into ASCII and store it as a Byte array.
        Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);             // Get a client stream for reading and writing.
       //  Stream stream = client.GetStream();    NetworkStream stream = client.GetStream();    // Send the message to the connected TcpServer. 
        stream.Write(data, 0, data.Length);    Console.WriteLine("Sent: {0}", message);             // Receive the TcpServer.response.    // Buffer to store the response bytes.
        data = new Byte[256];    // String to store the response ASCII representation.
        String responseData = String.Empty;    // Read the first batch of the TcpServer response bytes.
        Int32 bytes = stream.Read(data, 0, data.Length);
        responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
        Console.WriteLine("Received: {0}", responseData);