G
Guest
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.AcceptSocket();
incomingBuffer = new byte[1024]; // 1Kb
bytesRead = s.Receive(incomingBuffer);
string buffer = Encoding.ASCII.GetString(incomingBuffer);
totalBytesRead = fileBytes.Length;
int iCount = 1;
int lIndex = 0;
int iTemp = 1;
int iDivides = totalBytesRead / 100000;
int iRemander = totalBytesRead % 100000;
while (iCount <= iDivides)
{
FileStream fs = new FileStream(virtualDir + requestedFile, FileMode.Open,
FileAccess.Read, FileShare.Read);
BinaryReader reader = new BinaryReader(fs);
reader.Read(fileBytes, lIndex, (100000 * iCount));
if ((numBytes = s.Send(fileBytes, fileBytes.Length, 0)) == -1)
this.Log("Socket 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
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.AcceptSocket();
incomingBuffer = new byte[1024]; // 1Kb
bytesRead = s.Receive(incomingBuffer);
string buffer = Encoding.ASCII.GetString(incomingBuffer);
totalBytesRead = fileBytes.Length;
int iCount = 1;
int lIndex = 0;
int iTemp = 1;
int iDivides = totalBytesRead / 100000;
int iRemander = totalBytesRead % 100000;
while (iCount <= iDivides)
{
FileStream fs = new FileStream(virtualDir + requestedFile, FileMode.Open,
FileAccess.Read, FileShare.Read);
BinaryReader reader = new BinaryReader(fs);
reader.Read(fileBytes, lIndex, (100000 * iCount));
if ((numBytes = s.Send(fileBytes, fileBytes.Length, 0)) == -1)
this.Log("Socket 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