0

I'm sending file from smart device windows CE via wireless to PC , the file is sending by TCP, it works properly when I was testing it by deploy the application via active synchronize from my laptop. but when the application installed inside the device it didn't send the file and it show me the exception :A socket operation was attempted to an unreachable host the code is below

private void button1_Click(object sender, EventArgs e)
{
    string IPAddress = "10.1.1.102";
    string filPath = "\\student.XML";
    int PortNumber = 5656;

    SendTCP(filPath, IPAddress, PortNumber);            
}

public void SendTCP(string M, string IPA, Int32 PortN)
{
    byte[] SendingBuffer = null;
    TcpClient client = null;
    NetworkStream netstream = null;

    try
    {
        client = new TcpClient(IPA, PortN);
        MessageBox.Show("Connected to the Server...\n");

        netstream = client.GetStream();
        FileStream Fs = new FileStream(M, FileMode.Open, FileAccess.Read);
        int NoOfPackets = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(Fs.Length) / Convert.ToDouble(BufferSize)));

      //  progressBar1.Maximum = NoOfPackets;

        int TotalLength = (int)Fs.Length, CurrentPacketLength, counter = 0;
        for (int i = 0; i < NoOfPackets; i++)
        {
            if (TotalLength > BufferSize)
            {
                CurrentPacketLength = BufferSize;
                TotalLength = TotalLength - CurrentPacketLength;
            }
            else
                CurrentPacketLength = TotalLength;

            SendingBuffer = new byte[CurrentPacketLength];
            Fs.Read(SendingBuffer, 0, CurrentPacketLength);
            netstream.Write(SendingBuffer, 0, (int)SendingBuffer.Length);
        }

        // label1.Text = label1.Text + "Sent " + Fs.Length.ToString() + " bytes to the server";
        MessageBox.Show("Sent " + Fs.Length.ToString() + " bytes to the server");

        Fs.Close();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    finally
    {
        netstream.Close();
        client.Close();
    }
}

I don't Know how to fix this errors help please

Darko Kenda
  • 4,781
  • 1
  • 28
  • 31
batool hamwy
  • 3
  • 2
  • 4

1 Answers1

0

Are you sure the device is connected to the network and the destination IP is correct?

Note that when connected via ActiveSync/Windows Mobile Center, a separate network connection to the device is estabilished and the device get another (different) IP address via which it communicates to the host computer.

Darko Kenda
  • 4,781
  • 1
  • 28
  • 31
  • well the error is pretty self-explanatory: the client cannot find a network route to the destination. The network (connection) is most likely misconfigured somewhere. Have you tried pinging the device from the computer and vice versa? – Darko Kenda Apr 28 '13 at 23:14
  • yes, I'm sure that the device is connected to the network and I'm sure that the IP address is correct, what do you advice me to do?? – batool hamwy Apr 28 '13 at 23:15
  • have you checked the firewall on the host computer? – Darko Kenda Apr 28 '13 at 23:16
  • I have try pinging the device from my computer and vice versa it failed what to do ?? – batool hamwy Apr 28 '13 at 23:44
  • Check the firewall. Recheck the IP address configuration on the device. Check if the device can access the internet (if it's on an internet-connected network). – Darko Kenda Apr 28 '13 at 23:49