当第一个客户端连接到服务器时。向服务器端发送一个包,服务发接收到数据后,发送回到每个客户端。当第二个客户端连接到服务器时。同样向服务器端发送一个包,服务发接收到数据后,发送回到每个客户端。我目前是当第二个客户端连接并向服务器发送数据后,第一个的数据就被覆盖掉了。现在我的问题是,我怎么把第一个客户端发送的数据保存住,当第二个客户端连接后,可以把第一个和第二个的包也发送到每个客户端请给出代码,不盛感激!!

解决方案 »

  1.   

    用hashtable不就得了using System;
    using System.Collections;
    public class SamplesHashtable  {   public static void Main()  {      // Creates and initializes a new Hashtable.
          Hashtable myHT = new Hashtable();
          myHT.Add("First", "Hello");
          myHT.Add("Second", "World");
          myHT.Add("Third", "!");      // Displays the properties and values of the Hashtable.
          Console.WriteLine( "myHT" );
          Console.WriteLine( "  Count:    {0}", myHT.Count );
          Console.WriteLine( "  Keys and Values:" );
          PrintKeysAndValues( myHT );
       }
       public static void PrintKeysAndValues( Hashtable myList )  {
          IDictionaryEnumerator myEnumerator = myList.GetEnumerator();
          Console.WriteLine( "\t-KEY-\t-VALUE-" );
          while ( myEnumerator.MoveNext() )
             Console.WriteLine("\t{0}:\t{1}", myEnumerator.Key, myEnumerator.Value);
          Console.WriteLine();
       }
    }
    /* 
    This code produces the following output.myHT
      Count:    3
      Keys and Values:
        -KEY-    -VALUE-
        Third:    !
        Second:    World
        First:    Hello
    */