Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Problems sending data from windows CE

Started by artificial stupidity Oct 17, 2008 at 8:42 AM 0 replies 650+ views
Original Post
artificial stupidity
artificial stupidity
Hi! Im having a problem sending data from a pocket-pc with windows CE. I can only send about 30-40 bytes and then bytes disapears. The server recievs strings of the wrong length. :( Can someone help me? This is the client code:

TcpClient client = new TcpClient(ip, port);
NetworkStream ns = client.GetStream();

StreamWriter sw = new StreamWriter(ns);
StreamReader sr = new StreamReader(ns);


int len = Int32.Parse(textBox1.Text);

sw.WriteLine(len); // write the number of chars in the string to recieve.
sw.WriteLine(getData(len)); // get a random string of length len and send it. 
sw.Flush();


ns.Close();
client.Close();


this is the server:

// s is a tcpclient from an acceptance

NetworkStream ns = s.GetStream();
StreamReader sr = new StreamReader(ns);
StreamWriter sw = new StreamWriter(ns);

int bytes = Int32.Parse(sr.ReadLine());
            
string allData = sr.ReadLine();

if (allData.Length == bytes)
{
	Console.WriteLine("OK - Received " + allData.Length + " bytes");
} else {
	 Console.WriteLine("ERROR - Received " + allData.Length + " bytes");
}

sw.Flush();
ns.close();
client.close();


Billr17
Billr17
What is your 'string getData(int size)' function doing? You said it returns a random string. How are you producing this random string? Have you checked to verify the contents of the string prior to sending it over the network?

For instance, if your random string contains either a line feed character or a carriage return character that is followed by an line feed character in the middle of the string, 'ReadLine()' will not return the size that you are expecting. In this example, ReadLine would only return the first half of the string.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.