tags:

views:

36

answers:

0

I am involved in a project where I have to send string data to another computer using a 3G network. The severer is using C# and the client is using JAVA. Client side functions are working fine. But when it comes to the server side which uses C# I am having problems. I can read the input from the client with out any problem but sending is not successful.

I can send a simple string(one line) to the client with out any problems. But when I have to send multiple lines of strings it is not successful. Here is the C# code I am using.

using System; using System.Xml; using System.Net.Sockets;

namespace ReadXml1 {

class Class1
{

    static void Main(string[] args)
    {
        string fileName = "abc.xml";
        //  XPathDocument doc = new XPathDocument(fileName);
        //  XPathNavigator nav = doc.CreateNavigator();

        try
        {
            TcpClient tc = new TcpClient("10.16.68.225", 9500);// in the place of server, enter 
            //your java server's hostname or Ip
            Console.WriteLine("Server invoked");
            NetworkStream ns = tc.GetStream();
            //  StreamWriter sw = new StreamWriter(ns);
            using (StreamWriter sw = new StreamWriter(ns))
            {
                //sw.WriteLine("This is a text");
                //sw.Flush();
                // Create an isntance of XmlTextReader and call Read method to read the file
                XmlTextReader r = new XmlTextReader(fileName);
                r.Read();

                // If the node has value
                while (r.Read())
                {
                    if (r.NodeType == XmlNodeType.Element)
                    {
                        sw.WriteLine("<" + r.Name + ">"); sw.Flush();

                        Console.WriteLine("<" + r.Name + ">");
                        if (r.HasAttributes)
                        {
                            for (int i = 0; i < r.AttributeCount; i++)
                            {
                                sw.WriteLine("\tATTRIBUTE: " + r.GetAttribute(i)); sw.Flush();

                                Console.WriteLine("\tATTRIBUTE: " + r.GetAttribute(i));
                            }
                        }
                    }
                    else if (r.NodeType == XmlNodeType.Text)
                    {
                        sw.WriteLine("\tVALUE: " + r.Value); sw.Flush();
                        Console.WriteLine("\tVALUE: " + r.Value);
                    }
                }


                    StreamReader sr = new StreamReader(ns);
                    Console.WriteLine(sr.ReadLine());

            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
}

}