Hello,
I have a very strabge problem and dont know what to do. I wrote very simple code to varify the behavior of problem in some big project.
I run this Server Code in a Console Application on my PC:
class Program
{
private static TcpListener listener;
private static int port;
static void Main(string[] args)
{
port = 7000;
listener = new TcpListener(IPAddress.Any, port);
listener.Start();
Console.WriteLine("Server Started");
TcpClient client = listener.AcceptTcpClient();
Console.WriteLine("Client Connected");
NetworkStream ns = client.GetStream();
byte[] data = Encoding.ASCII.GetBytes("Hello");
ns.Write(data, 0, data.Length);
ns.Flush();
Console.WriteLine("Data Sent");
ns.Close();
client.Close();
listener.Stop();
Console.ReadLine();
}
}
And I Run this Client Code from My Pocket PC in Console Application:
class Program
{
private static int port;
private static TcpClient client;
static void Main(string[] args)
{
port = 7000;
client = new TcpClient();
Console.WriteLine("Connecting");
client.Connect(IPAddress.Parse( "210.2.164.223"), port);
Console.WriteLine("Connected");
NetworkStream ns = client.GetStream();
byte[] data = new byte[50];
Console.WriteLine("Reading Message");
int readBytes = ns.Read(data, 0, data.Length); // Reutrns 0
string message = Encoding.ASCII.GetString(data, 0, readBytes);
Console.WriteLine(message);
ns.Close();
client.Close();
Console.ReadLine();
}
}
Server Output:
Server Started
Client Connected
Data Sent
Client Output:
Connecting
Connected
Reading Message
// Here Blank Massage is Received
Note:
If I use the same client code on PC in Console Application, All works fine and Client Receives data!
If I use the same client code on Pocket PC through GPRS Connection then also it works fine!
But when I use the same client code on Pocket PC which is connected to My PC through Cradle I dound the above mentioned output with 0 length data received.
Conclusion:
All worked fine a few days back before I Installed my Windows. It seems like some problem with IP Addresses!
My PC Gets 2 IP Addresses one from DSL Internet Modem and One from the Cradle of Pocket PC when Device is on the Cradle; Before Windows Installation When I used to Query for IP Addresses of machine It gave me DSL Modems IP Address at index 0 and Cradle's connection IP Address at 1 index but after Windows installation I get the inverse, First Cradle's Connection IP and second DSl Modem's IP though Dns.GetHostAddresses(Environment.MachineName).AddressList;
I wasted 8 hours to find all this and then it came to my mind to write a small application to check from where problem is arisen but got the conclusion that my code is fine, There is some other conflict which is sucking my mind badly.
Its not feasible for me to waste much time to make an update to application then connect th GPRS then disconnect it to update it and then connect again to test and so on.
In past I just used Cradles Connection, All I needed to do was to put my device on cradle in morning and do all the Update, Test and so on, And then take it off from the Cradle. But now It S****!
Can Anybody tell me how to fix this problem
I'll be really thankful to you to solve this issue!
Best Regards,
.NET Development27
|