Hello,
I need some help. I am trying to write my own web server for serving up
large files
on my own network. I am using FileStream, BinaryReader, TcpClient, and
Sockets.
I am trying to break up the large file and send it a chunck at a time. But
I keep getting
and error stating that "Error occured: An operation on a socket could not be
performed
because the system lacked sufficient buffer space or because a queue was
full".
Here is some of the code:
Socket s;
byte[] incomingBuffer;
s = this.listener.A cceptSocket();
incomingBuffer = new byte[1024]; // 1Kb
bytesRead = s.Receive(incom ingBuffer);
string buffer = Encoding.ASCII. GetString(incom ingBuffer);
totalBytesRead = fileBytes.Lengt h;
int iCount = 1;
int lIndex = 0;
int iTemp = 1;
int iDivides = totalBytesRead / 100000;
int iRemander = totalBytesRead % 100000;
while (iCount <= iDivides)
{
FileStream fs = new FileStream(virt ualDir + requestedFile, FileMode.Open,
FileAccess.Read , FileShare.Read) ;
BinaryReader reader = new BinaryReader(fs );
reader.Read(fil eBytes, lIndex, (100000 * iCount));
if ((numBytes = s.Send(fileByte s, fileBytes.Lengt h, 0)) == -1)
this.Log("Socke t error: Cannot send packet");
else
this.Log(String .Format("Bytes sent: {0}", numBytes)); lIndex +=
(100000 + iTemp);
iTemp = 0;
iCount++;
reader.Close();
fs.Close();
}
Can anyone give any direction? If I'm not going at it the right way,please
let me know.
One of the reasons I'm trying to break up the is because my app kept trying
to load the
whole thing into memory before it sent the file. So my memory for the app
would grow to
over a gig. I just need some way to read in the file and then stream it out.
Or stream it
as I read it.
Thanks,
Michael 4 1982
Michael wrote:
Hello,
I need some help. I am trying to write my own web server for serving up
large files
on my own network. I am using FileStream, BinaryReader, TcpClient, and
Sockets.
I am trying to break up the large file and send it a chunck at a time. But
I keep getting
and error stating that "Error occured: An operation on a socket could not be
performed
because the system lacked sufficient buffer space or because a queue was
full".
Here is some of the code:
Socket s;
byte[] incomingBuffer;
s = this.listener.A cceptSocket();
incomingBuffer = new byte[1024]; // 1Kb
bytesRead = s.Receive(incom ingBuffer);
string buffer = Encoding.ASCII. GetString(incom ingBuffer);
What do you do here? You know that characters are 16 bit values, right?
And you know that the ASCII encoding only uses 7-bit character codes, right?
How are you going to use the string?
>
totalBytesRead = fileBytes.Lengt h;
What does fileBytes contain? How large is it? The way that you use it,
it looks like it contains all the data from the file. Wasn't that what
you were trying to avoid?
int iCount = 1;
int lIndex = 0;
int iTemp = 1;
int iDivides = totalBytesRead / 100000;
int iRemander = totalBytesRead % 100000;
while (iCount <= iDivides)
{
FileStream fs = new FileStream(virt ualDir + requestedFile, FileMode.Open,
FileAccess.Read , FileShare.Read) ;
Why are you opening and closing the file for each iteration of the loop?
>
BinaryReader reader = new BinaryReader(fs );
reader.Read(fil eBytes, lIndex, (100000 * iCount));
As you are increasing iCount for every iteration in the loop, you will
be reading larger and larger pieces of the file.
As you are increasing lIndex for every iteration in the loop, you will
be reading several copies of some data into different locations of the
array.
How large is fileBytes? If you want to fit all that data into the array,
it has to be much larger than the file.
>
if ((numBytes = s.Send(fileByte s, fileBytes.Lengt h, 0)) == -1)
You are sending the entire contents of the array fileBytes, not just
what you read into it. That means that you will be sending several
copies of part of the file mixed with the data that was in the array
from the beginning.
this.Log("Socke t error: Cannot send packet");
else
this.Log(String .Format("Bytes sent: {0}", numBytes)); lIndex +=
(100000 + iTemp);
Why are you increasing lIndex by 100001 the first time?
>
iTemp = 0;
iCount++;
reader.Close();
fs.Close();
}
Can anyone give any direction? If I'm not going at it the right way,please
let me know.
One of the reasons I'm trying to break up the is because my app kept trying
to load the
whole thing into memory before it sent the file. So my memory for the app
would grow to
over a gig. I just need some way to read in the file and then stream it out.
Or stream it
as I read it.
Thanks,
Michael
--
Göran Andersson
_____ http://www.guffa.com
Then what should I do?
"Göran Andersson" wrote:
Michael wrote:
Hello,
I need some help. I am trying to write my own web server for serving up
large files
on my own network. I am using FileStream, BinaryReader, TcpClient, and
Sockets.
I am trying to break up the large file and send it a chunck at a time. But
I keep getting
and error stating that "Error occured: An operation on a socket could not be
performed
because the system lacked sufficient buffer space or because a queue was
full".
Here is some of the code:
Socket s;
byte[] incomingBuffer;
s = this.listener.A cceptSocket();
incomingBuffer = new byte[1024]; // 1Kb
bytesRead = s.Receive(incom ingBuffer);
string buffer = Encoding.ASCII. GetString(incom ingBuffer);
What do you do here? You know that characters are 16 bit values, right?
And you know that the ASCII encoding only uses 7-bit character codes, right?
How are you going to use the string?
totalBytesRead = fileBytes.Lengt h;
What does fileBytes contain? How large is it? The way that you use it,
it looks like it contains all the data from the file. Wasn't that what
you were trying to avoid?
int iCount = 1;
int lIndex = 0;
int iTemp = 1;
int iDivides = totalBytesRead / 100000;
int iRemander = totalBytesRead % 100000;
while (iCount <= iDivides)
{
FileStream fs = new FileStream(virt ualDir + requestedFile, FileMode.Open,
FileAccess.Read , FileShare.Read) ;
Why are you opening and closing the file for each iteration of the loop?
BinaryReader reader = new BinaryReader(fs );
reader.Read(fil eBytes, lIndex, (100000 * iCount));
As you are increasing iCount for every iteration in the loop, you will
be reading larger and larger pieces of the file.
As you are increasing lIndex for every iteration in the loop, you will
be reading several copies of some data into different locations of the
array.
How large is fileBytes? If you want to fit all that data into the array,
it has to be much larger than the file.
if ((numBytes = s.Send(fileByte s, fileBytes.Lengt h, 0)) == -1)
You are sending the entire contents of the array fileBytes, not just
what you read into it. That means that you will be sending several
copies of part of the file mixed with the data that was in the array
from the beginning.
this.Log("Socke t error: Cannot send packet");
else
this.Log(String .Format("Bytes sent: {0}", numBytes)); lIndex +=
(100000 + iTemp);
Why are you increasing lIndex by 100001 the first time?
iTemp = 0;
iCount++;
reader.Close();
fs.Close();
}
Can anyone give any direction? If I'm not going at it the right way,please
let me know.
One of the reasons I'm trying to break up the is because my app kept trying
to load the
whole thing into memory before it sent the file. So my memory for the app
would grow to
over a gig. I just need some way to read in the file and then stream it out.
Or stream it
as I read it.
Thanks,
Michael
--
Göran Andersson
_____ http://www.guffa.com
On Thu, 19 Jul 2007 07:38:10 -0700, Michael
<Mi*****@discus sions.microsoft .comwrote:
Then what should I do?
For receiving, you should:
* not convert your byte data to ASCII characters
There may be other things you should or should not do, but since you
didn't post all of your receiving code, it's hard to comment on what else
is wrong.
For sending, you should:
* calculate bytes read based on actual bytes read, rather than some
other variable or property
* open the file once, rather than each time through your loop
* only read the same amount of bytes each time you read
* update your index to read from based on the bytes read, rather than
on some incorrect calculation
* not have arbitrary things like "iTemp" that add 1 for no good reason
to some calculation
There may be other things you need to change, but I'd start with the above
list and see what you have at that point.
Pete
On Tue, 17 Jul 2007 09:00:01 -0700, Michael
<Mi*****@discus sions.microsoft .comwrote:
>Hello,
I need some help. I am trying to write my own web server for serving up large files on my own network. I am using FileStream, BinaryReader, TcpClient, and Sockets. I am trying to break up the large file and send it a chunck at a time. But I keep getting and error stating that "Error occured: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full".
Here is some of the code:
Socket s; byte[] incomingBuffer;
s = this.listener.A cceptSocket();
incomingBuff er = new byte[1024]; // 1Kb bytesRead = s.Receive(incom ingBuffer); string buffer = Encoding.ASCII. GetString(incom ingBuffer);
totalBytesRe ad = fileBytes.Lengt h; int iCount = 1; int lIndex = 0; int iTemp = 1; int iDivides = totalBytesRead / 100000; int iRemander = totalBytesRead % 100000; while (iCount <= iDivides) {
FileStream fs = new FileStream(virt ualDir + requestedFile, FileMode.Open, FileAccess.Rea d, FileShare.Read) ;
BinaryReader reader = new BinaryReader(fs );
reader.Read(fil eBytes, lIndex, (100000 * iCount));
if ((numBytes = s.Send(fileByte s, fileBytes.Lengt h, 0)) == -1) this.Log("Socke t error: Cannot send packet");
else
this.Log(String .Format("Bytes sent: {0}", numBytes)); lIndex += (100000 + iTemp);
iTemp = 0;
iCount++;
reader.Close();
fs.Close(); }
Can anyone give any direction? If I'm not going at it the right way,please let me know. One of the reasons I'm trying to break up the is because my app kept trying to load the whole thing into memory before it sent the file. So my memory for the app would grow to over a gig. I just need some way to read in the file and then stream it out.
Or stream it as I read it.
Thanks, Michael
Is there any particular reason you're not using plain old FTP?
-- http://bytes.thinkersroom.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 must be the only method that users
receive image files.
|
by: Vanga Sasidhar |
last post by:
Hi All,
I am developing a program in Visual Basic .NET 2002. There are some
videos in AVI format. For the protection of these AVI files i encrypted my
files with the use of DES algorithm in the system.security.cryptography
namespace. My program developed in VB.NET will have all the passwords for
these AVI files and my program only can open these files using the same
algorithm. I used Windows Media Player control in my application to show...
|
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 knowledge bout all
this things that needed...can someone give me a rough guideline bout
what should i do step-by-step... such as..what database should i
use...how can i store or create a database that can hold my multimedia
files?
i really do need ur...
|
by: Manuel Alves |
last post by:
Hi,
Is it possible to store media files (like windows .wmv) on SQL Server 2005
and stream it back to the client via media server (not just download it)?
Regards,
Manuel Alves
|
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 are a lot smaller in size, but they do
not stream, a user has to download the file before listening to it.
Which format would you recommend for good to high quality audio streaming?
Should RealAudio files stream? If so how can I get them to...
| |
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 from video..
doubts:
how to upload the video files to web server?
|
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 I read this post I would surely think - pick up a manual and
start reading, however we have no time for this since this is one of several
demands a customer added on the last minute of a projecct.
|
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 text message to each other but now
i want to send video file and play that file on other end...I know the code
how to send the stream over the network but basic problem is how open that
file as a stream.
Thanks
|
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 in IE, Firefox and Opera on
windows, and it works on a Mac with Firefox and Opera. But this fails in Safari with the generic message "A network
error occurred while accessing this document".
Here is a link to try out ...
|
by: Chris Kennedy |
last post by:
I want to put some mp3 files on a server and stream them through a flash
player. Is there any way of locking down the files so only the flash player
can see and access them - i.e. to stop people downloading them. It's a very
small project so I really want a cheap/ open source solution. Might be a
nice excuse to look at Silverlight :) Not sure whether the Silverlight will
solve the problem.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |