title: Cannot access a disposed object. in c# client & Server
body: <h2>I had fix my Problem Cannot access a disposed object. in c# client &amp; Server</h2>
  
  <p>Following Points I Used.</p>
  
  <ul>
  <li>Used Using for Scope Limitation</li>
  <li>i am not Closed Socket Object</li>
  </ul>
  
  <p>class Client
      {
          static void Main(string[] args)
          {
              Console.Title = "Client Chat";
              byte[] bytes = new byte[1024];// data buffer for incoming data
              string data = null;</p>
  
  <pre><code>        // connect to a Remote device
          try
          {
              // Establish the remote end point for the socket
              IPHostEntry ipHost = Dns.Resolve("localhost");
              IPAddress ipAddr = ipHost.AddressList[0];
              IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 95);
              using (Socket Socketsender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
              {
                  Socketsender.Connect(ipEndPoint);
  
  
                  Console.WriteLine("\n\n\tSocket Connecting To Java Server...." + Socketsender.RemoteEndPoint.ToString());                                   
  
                  while (true)
                  {
                      Console.Write("\n\n\tClient::");
                      string theMessage = Console.ReadLine();
                      byte[] msg = Encoding.ASCII.GetBytes(theMessage);
                      // Send the data through the socket
  
  
                      int bytesSent = Socketsender.Send(msg);
                      //Recieved from Java Server Message
                      int bytesRec = Socketsender.Receive(bytes);
                      Console.WriteLine("\n\n\tJava Server Says:: {0}", Encoding.ASCII.GetString(bytes, 0, bytesRec));              
  
                  }
                  //Socketsender.Close();
  
              }
  
          }
  
          catch (Exception e)
          {
              Console.WriteLine(e.Message);
          }
  
          Console.ReadLine();
      }
  
  
  }
  </code></pre>