Flash (SWF) from Web Server

E

earl.bobby

I'm creating a webserver to run from a CD. I've found
http://www.adp-gmbh.ch/win/misc/webserver.html which is my starting
block. I've really made two modifications. First adding the
appropriate content-type in the headers whether I'm delivering
html/css/jpeg/etc. The second is reading those simple html/css files
as opposed to having the html hard coded. My problem occurs when
trying to display flash files. I am also only able to reproduce the
problem in IE, not Firefox. Trying to view the swf prompts for a
download of the file, which does fail if you try it. I know this isn't
some setting in IE b/c other swf's load fine.

My best guess is how I'm reading the files?

I've included below the two code modifications from the original
source.

main.cpp.......... Read Files instead of hard coding html

std::string strLine;
std::string strResponse;
std::string strChapter = r->path_;
ifstream objFile;

// COMMENT: Process Empty Request
if (strChapter == "/")
{ strChapter = "/index.htm"; }

// COMMENT: Add TSLM Directory, Remove Leading Slash
strChapter = "tslm\\" + strChapter.substr(1,strChapter.length());

// COMMENT: Open File
objFile.open(strChapter.c_str(), ios::eek:ut | ios::binary);
if (objFile.is_open())
{

// COMMENT: Loop Through File
while (!objFile.eof())
{
getline (objFile,strLine);
strResponse += strLine + "\n";
}

// COMMENT: Close Binary Connection
objFile.close();
}
else
{ strResponse = ""; }

// COMMENT: Return Response
r->answer_ = strResponse;


WebServer.cpp...... Fixed Content-Type Headers...

// COMMENT: Determine Content Type
if(strExt == (".htm") || strExt == (".html"))
strType = "text/html";
else if(strExt == (".css"))
strType = "text/css";
else if(strExt == (".js"))
strType = "application/x-javascript";
else if(strExt == (".swf"))
strType = "application/x-shockwave-flash";
else if(strExt == (".txt"))
strType = "text/plain";
else if(strExt == (".jpg") || strExt == (".jpeg"))
strType = "image/jpeg";
else if(strExt == (".gif"))
strType = "image/gif";
else
strType = "application/octet-stream";


Any help or insight as to why this fails would be more than appreciated!
 
S

Salt_Peter

I'm creating a webserver to run from a CD. I've found
http://www.adp-gmbh.ch/win/misc/webserver.html which is my starting
block. I've really made two modifications. First adding the
appropriate content-type in the headers whether I'm delivering
html/css/jpeg/etc. The second is reading those simple html/css files
as opposed to having the html hard coded. My problem occurs when
trying to display flash files. I am also only able to reproduce the
problem in IE, not Firefox. Trying to view the swf prompts for a
download of the file, which does fail if you try it. I know this isn't
some setting in IE b/c other swf's load fine.

My best guess is how I'm reading the files?

I've included below the two code modifications from the original
source.

main.cpp.......... Read Files instead of hard coding html

std::string strLine;
std::string strResponse;
std::string strChapter = r->path_;
ifstream objFile;

// COMMENT: Process Empty Request
if (strChapter == "/")
{ strChapter = "/index.htm"; }

// COMMENT: Add TSLM Directory, Remove Leading Slash
strChapter = "tslm\\" + strChapter.substr(1,strChapter.length());

// COMMENT: Open File
objFile.open(strChapter.c_str(), ios::eek:ut | ios::binary);

objFile.open(strChapter.c_str(), ios::in | ios::binary);
 
G

Gavin Deane

I'm creating a webserver to run from a CD. I've found
http://www.adp-gmbh.ch/win/misc/webserver.html which is my starting
block. I've really made two modifications. First adding the
appropriate content-type in the headers whether I'm delivering
html/css/jpeg/etc. The second is reading those simple html/css files
as opposed to having the html hard coded. My problem occurs when
trying to display flash files. I am also only able to reproduce the
problem in IE, not Firefox. Trying to view the swf prompts for a
download of the file, which does fail if you try it. I know this isn't
some setting in IE b/c other swf's load fine.

My best guess is how I'm reading the files?

I've included below the two code modifications from the original
source.

main.cpp.......... Read Files instead of hard coding html

// COMMENT: Loop Through File
while (!objFile.eof())
{
getline (objFile,strLine);
strResponse += strLine + "\n";
}

Any help or insight as to why this fails would be more than appreciated!

I don't know if it has anything to do with what you're seeing, but you
say you suspect that how you read the files might be the problem. One
thing leapt out:

while (!objFile.eof())

is not how you use eof when reading from a stream.
http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.5

Gavin Deane
 
E

earl.bobby

You're right, that should be ios::in

I've corrected that but actually posted a slightly older version of my
code. Thank you though!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top