Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

HttpListener based app loading Java Applet into html page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Reg - 04 Sep 2007 19:20 GMT
I have a following code in HttpRequestListener's ProcessRequest method which
is a Windows
Console Application. I'm trying to read html page with browser (Opera) and
html file contains tags to include
Java Applet jar too,

for (int i = 0; i < numRequestsToBeHandled; i++)
{
   HttpListenerResponse response = null;
  try
  {
  // GetContext blocks while waiting for a request.
   HttpListenerContext context = listener.GetContext();
  // Create the response.
  response = context.Response;
  int pos = context.Request.Url.AbsoluteUri.LastIndexOf("/");
  string file = context.Request.Url.AbsoluteUri.Substring(++pos);
  byte[] buffer = new byte[32768];
  // Reading html and Java Applet Jar file from file system
  FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read);
  int read = stream.Read(buffer, 0, buffer.Length);
  stream.Close();
  response.ContentLength64 = buffer.Length;
  System.IO.Stream output = response.OutputStream;
  output.Write(buffer, 0, buffer.Length);
  output.Close();

Problem is that I get "Invalid Bytecode" error in Opera and IE shows
nothing.

Something missing, can anyone tell me what?

Cheers,
Peter Bromberg [C# MVP] - 05 Sep 2007 01:28 GMT
If the Html file contains tags to load the jar file, that's not what your
code is doing.
Your code:

int pos = context.Request.Url.AbsoluteUri.LastIndexOf("/");
string file = context.Request.Url.AbsoluteUri.Substring(++pos);

-- assumes that the request is directly for the jar file alone. What you
really need to be doing is serving the Html file that the request is asking
for, then you would get a subrequest  from the browser reading the jar file
and you would need to serve that.
-- Peter
Recursion: see Recursion
site:  http://www.eggheadcafe.com
unBlog:  http://petesbloggerama.blogspot.com
BlogMetaFinder:    http://www.blogmetafinder.com

> I have a following code in HttpRequestListener's ProcessRequest method which
> is a Windows
[quoted text clipped - 29 lines]
>
> Cheers,

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.