473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Streaming files over http


I am working on a project where I want to send at file from a Win CE device
to a receiving PC using the HTTP protocol.
For testing purpose I made a simple test app on my PC (code below).

The problem is that only the first 8760 bytes of the file is transfered. I
have tried several times and the received file is always 8760 bytes.
I have tested with several files (10k -> 200k).

My receiving application works very well with other application. I have
transfered files over 1MB. So there must be something with my send
application.
I have checked that the size in the header message is received correctly at
the receiving end but the actual stream is to short. The size of the stream
buffer on the sending side is also correct. So it seems like there is some
problems with the "low level" transfer. Is there some setting I may have
missed?

Does someone have any ideas?
Thanks in advance for any comments


public void SendFile()
{
try
{
HttpWebRequest request=(HttpWebRequest)
WebRequest.Create("http://192.168.1.10:16000/Send/test.xml);

request.ContentType="text/xml";
request.Method = "POST";
request.Timeout = 10000;
FileStream fs = new FileStream("D:\\Temp\\test.xml", FileMode.Open,
FileAccess.Read);
request.ContentLength = fs.Length;
fs.Close();
request.AllowWriteStreamBuffering = true;

request.BeginGetRequestStream(new AsyncCallback(ReadCallback),
request);

allDone.WaitOne();

HttpWebResponse httpWResp = (HttpWebResponse)request.GetResponse();
httpWResp.Close();
}
catch (System.Net.WebException escWeb)
{
if (escWeb.Response != null)
escWeb.Response.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}//------------------------------------------------------------------------
private static void ReadCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest request =
(HttpWebRequest)asynchronousResult.AsyncState;

request.AllowWriteStreamBuffering = true;

Stream postStream = request.EndGetRequestStream(asynchronousResult);

FileStream fs = new FileStream("D:\\temp\\test.xml", FileMode.Open,
FileAccess.Read, FileShare.None);
byte[] buf = new byte[fs.Length];
fs.Read(buf, 0, (int)fs.Length);

postStream.Write(buf, 0, buf.Length);

postStream.Close();
fs.Close();
allDone.Set();
}
catch (System.Net.WebException escWeb)
{
if (escWeb.Response != null)
escWeb.Response.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}//------------------------------------------------------------------------

Nov 16 '05 #1
3 3850

"Stig-Arne Basberg" <sab(a)isystem.no> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...

I am working on a project where I want to send at file from a Win CE device to a receiving PC using the HTTP protocol.
For testing purpose I made a simple test app on my PC (code below).

The problem is that only the first 8760 bytes of the file is transfered. I
have tried several times and the received file is always 8760 bytes.
I have tested with several files (10k -> 200k).

My receiving application works very well with other application. I have
transfered files over 1MB. So there must be something with my send
application.
I have checked that the size in the header message is received correctly at the receiving end but the actual stream is to short. The size of the stream buffer on the sending side is also correct. So it seems like there is some
problems with the "low level" transfer. Is there some setting I may have
missed?


Why are you doing an async receive? You are turning right around and
waiting for it to complete, so you're just making two threads do the work of
one.

Use simple blocking IO, and I bet you'll find the problem right away.

David
Nov 16 '05 #2

"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:eW**************@tk2msftngp13.phx.gbl...

"Stig-Arne Basberg" <sab(a)isystem.no> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...

I am working on a project where I want to send at file from a Win CE device
to a receiving PC using the HTTP protocol.
For testing purpose I made a simple test app on my PC (code below).

The problem is that only the first 8760 bytes of the file is transfered. I have tried several times and the received file is always 8760 bytes.
I have tested with several files (10k -> 200k).

My receiving application works very well with other application. I have
transfered files over 1MB. So there must be something with my send
application.
I have checked that the size in the header message is received correctly

at
the receiving end but the actual stream is to short. The size of the

stream
buffer on the sending side is also correct. So it seems like there is some problems with the "low level" transfer. Is there some setting I may have
missed?


Why are you doing an async receive? You are turning right around and
waiting for it to complete, so you're just making two threads do the work

of one.

Use simple blocking IO, and I bet you'll find the problem right away.

David


Thanks for the replay.

I am quit new to the .net framework and I don't have to much experience
working with sockets. So I am not sure I understand what you mean.

I made an other simple test (code below). But with the same result. Only
8760 bytes transfered.
public void SendFile()
{
try
{
HttpWebRequest request=(HttpWebRequest)
WebRequest.Create("http://192.168.1.10/Send/test.xml);

request.ContentType="text/xml";
request.Method = "POST";
request.Timeout = 10000;

FileStream fs = new FileStream("D:\\Temp\\test.xml", FileMode.Open,
FileAccess.Read);
request.ContentLength = fs.Length;

byte[] buf = new byte[fs.Length];
fs.Read(buf, 0, (int)fs.Length);

Stream st = request.GetRequestStream();
st.Write(buf, 0, buf.Length);
st.Flush();
st.Close();
fs.Close();
}
catch (System.Net.WebException escWeb)
{
if (escWeb.Response != null)
escWeb.Response.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}

Nov 16 '05 #3
A Read operation on the stream is not guaranteed to return the entire length
even if you pass in a buffer big enough. You need to check the return value
that gives the number of bytes read and if there more to be read, read
again.

Typically, you'll have all stream read operations in a while loop that keeps
checking if you have read all that you wanted to read.

HTH

-vJ

"Stig-Arne Basberg" <sab(a)isystem.no> wrote in message
news:eQ*************@tk2msftngp13.phx.gbl...

"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:eW**************@tk2msftngp13.phx.gbl...

"Stig-Arne Basberg" <sab(a)isystem.no> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...
>
> I am working on a project where I want to send at file from a Win CE

device
> to a receiving PC using the HTTP protocol.
> For testing purpose I made a simple test app on my PC (code below).
>
> The problem is that only the first 8760 bytes of the file is
> transfered. I > have tried several times and the received file is always 8760 bytes.
> I have tested with several files (10k -> 200k).
>
> My receiving application works very well with other application. I have
> transfered files over 1MB. So there must be something with my send
> application.
>
>
> I have checked that the size in the header message is received
> correctly

at
> the receiving end but the actual stream is to short. The size of the

stream
> buffer on the sending side is also correct. So it seems like there is some > problems with the "low level" transfer. Is there some setting I may
> have
> missed?
>


Why are you doing an async receive? You are turning right around and
waiting for it to complete, so you're just making two threads do the work

of
one.

Use simple blocking IO, and I bet you'll find the problem right away.

David


Thanks for the replay.

I am quit new to the .net framework and I don't have to much experience
working with sockets. So I am not sure I understand what you mean.

I made an other simple test (code below). But with the same result. Only
8760 bytes transfered.
public void SendFile()
{
try
{
HttpWebRequest request=(HttpWebRequest)
WebRequest.Create("http://192.168.1.10/Send/test.xml);

request.ContentType="text/xml";
request.Method = "POST";
request.Timeout = 10000;

FileStream fs = new FileStream("D:\\Temp\\test.xml", FileMode.Open,
FileAccess.Read);
request.ContentLength = fs.Length;

byte[] buf = new byte[fs.Length];
fs.Read(buf, 0, (int)fs.Length);

Stream st = request.GetRequestStream();
st.Write(buf, 0, buf.Length);
st.Flush();
st.Close();
fs.Close();
}
catch (System.Net.WebException escWeb)
{
if (escWeb.Response != null)
escWeb.Response.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Markus Ernst | last post by:
Hi I know this question is rather HTTP related than PHP, but I did not find an HTTP group on my news server. I deliver some files with the following PHP syntax: header('Content-Description:...
3
by: A.M-SG | last post by:
Hi, I have a ASP.NET aspx file that needs to pass large images from a network storage to client browser. The requirement is that users cannot have access to the network share. The aspx file...
6
by: | last post by:
Hi all, is there a better way to stream binary data stored in a table in sql 2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We noticed that in certain heavy load scenarios,...
1
by: adiela | last post by:
hello everyone..i would like to ask something regarding my project.. i've been planning to develop a website using asp code for streaming multimedia features...unfortunatly...i have zero...
2
by: Cerebral Believer | last post by:
Hi All, I plan to use streaming audio on my site. I had uploaded some .mp3's as part of a trial, and these streamed very badly so I tried .ram (RealAudio) files instead. The RealAudio files...
8
by: poorna | last post by:
hi all i want to upload the video files to the server.. then i encode all the video files into flv files ... and then i am go to streaming ... in the mean while i create the thumbnail image...
4
by: Daniel Marious | last post by:
Hi, I'm looking for a .Net/COM component which would allow a .Net programmer with no streaming experience to be able to save online streams to local resources (files or to DB). I know that if...
8
by: Amjad | last post by:
Hi i am writing a application where i want to browse video file and copy data into stream and send that stream over network...I have develop P2P windows application where i successfully transfer...
5
by: Jim Bancroft | last post by:
Hi everyone, We've have files we'd like to store in a SQL Server blob or text column and make available online for our clients. Instead of linking to a document sitting on a file server, we...
3
by: Brad | last post by:
I have an aspx page that is sending pdf files to client browsers: it uses a filestream to read the pdf file and response.binarywrite to send content to the browser. This has worked great for years...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.