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