DataSet & NetworkStream in C#
<p>I want to sent DataTable from Server to Client using XML file in C#. I have used following code at server side</p>

<pre><code>DataSet ds = new DataSet();
ds.WriteXml(nw, XmlWriteMode.WriteSchema);
</code></pre>

<p>where nw is NetworkStream at Server</p>

<p>and following code is at Client side</p>

<pre><code>DataSet ds = new DataSet();
ds.ReadXml(clientSockStream, XmlReadMode.ReadSchema);
</code></pre>

<p>The server is sending data but at client side the program gets halted.
Server Side:</p>

<pre><code>tcpserver = new TcpListener(IPAddress.Any, 4444);
tcpserver.Start();
Socket serverSocket = tcpserver.AcceptSocket(); // accepting connection
    if (serverSocket.Connected)
    {
        serversockstream = new NetworkStream(serverSocket);
        serverStreamReader = new StreamReader(serversockstream);
        serverStreamWriter = new StreamWriter(serversockstream);
        handleClinet client = new handleClinet(); 
        client.startClient(serverStreamReader, serversockstream,serverStreamWriter);
    }

    public void startClient(StreamReader streamReader, NetworkStream ser, StreamWriter streamWriter)
    {
        this.sread = streamReader;
        this.swrite = streamWriter;
        this.nwstram = ser;
        Thread ctThread = new Thread(handleClients);
        ctThread.Start();
    }

    private void handleClients()
    {
        // Creating Dummy DataTable to send to Client...
        DataSet ds = new DataSet();
        DataTable d = new DataTable();
        d.Columns.Add("Name");
        d.Columns.Add("City");
        d.Rows.Add("John","USA");

        ds.Tables.Add(d);

        try
        {    

            while ((true))
            {
                String mystr = sread.ReadLine();
                if (mystr.Equals("sendTable"))
                    break;
            }
            swrite.WriteLine("done");
            swrite.Flush();
            if(nwstram.CanWrite)
            {
                MessageBox.Show("it can write...");
                ds.WriteXml(nwstram, XmlWriteMode.IgnoreSchema);
            }
            nwstram.Flush();
            MessageBox.Show("XML Sent");

        }
</code></pre>

<p>Client Side:</p>

<pre><code>    tcpClient = new TcpClient("127.0.0.1", 4444);

    IPHostEntry ip = Dns.GetHostEntry("127.0.0.1");
    //get a network stream from server
    clientSockStream = tcpClient.GetStream();
    clientStreamReader = new StreamReader(clientSockStream);
    clientStreamWriter = new StreamWriter(clientSockStream);

    private void button2_Click(object sender, EventArgs e)
    {
        try
        {
            clientStreamWriter.WriteLine("sendTable");
            clientStreamWriter.Flush();
            DataSet ds = new DataSet();
            String str = "";
            while (true)
            {
                str = clientStreamReader.ReadLine();
                if (str.Equals("done"))
                    break;

            }
            //MessageBox.Show("Client :" + str);
            if (clientSockStream.CanRead)
            {
                ds.ReadXml(clientSockStream, XmlReadMode.IgnoreSchema);
            }
        }
        dataGridView1.DataSource = ds.Tables[0];
    }
</code></pre>

<p>Assume that all catch blocks and necessary variables have declared ..
Plz reply..</p>
