troubleshooting Question

how to develop TCP Server for Win mobile device in visual c# 2005

Avatar of SciFiFreak
SciFiFreak asked on
Smartphone ProgrammingTCP/IP
2 Comments1 Solution495 ViewsLast Modified:
I want to develop a tcp server (pocket pc 2003 application)which has to run in the win mobile 2003 device(and at present in the simulator)
and tcp client (normal windows application)which runs on my computer and connect to this tcp server
using visual c# 2005.I have .net compact framework 2.0 on my computer.
I have two questions-
1)which ip shoild i use for the server??
2)I am using the following code for the server but it gives an error -connection refused by the server
private void button2_Click(object sender, EventArgs e)
            // Set the TcpListener on port 13000.
            Int32 port = 13000;
            IPAddress Addr = IPAddress.Parse("");
            TcpListener server = new TcpListener(Addr,port);

            // Start listening for client requests.
            // Buffer for reading data
            Byte[] bytes = new Byte[256];
            String data = null;

            // Enter the listening loop.
            while (true)
                //MessageBox.Show("waiting for a connection... ");
                //Perform a blocking call to accept requests.
                // You could also user server.AcceptSocket() here.
                TcpClient client = server.AcceptTcpClient();

                data = null;

                // Get a stream object for reading and writing
                NetworkStream stream = client.GetStream();

                Int32 i;

                // Loop to receive all the data sent by the client.
                while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                     // Translate data bytes to a ASCII string.
                     data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
                     //MessageBox.Show(String.Format("Received: {0}", data));

                     // Process the data sent by the client.
                     data = data.ToUpper();

                     Byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);

                     // Send back a response.
                     stream.Write(msg, 0, msg.Length);
                     textBox1.Text = String.Format("Sent: {0}", data);

                    // Shutdown and end connection


any suggestions would be appreciated


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros