Hello people. I am using a MyTcpListener as a webserver locally on my PC. I am trying to get my images to show when I run the program and use my firefox to punch in the IP Address. The images are in the bin folder as well as the HTML file is. My text shows up but my images wont. Here is my code so far. - using System;
-
using System.IO;
-
using System.Net;
-
using System.Net.Sockets;
-
using System.Text;
-
-
-
class MyTcpListener
-
{
-
public static void Main()
-
{
-
TcpListener server = null;
-
try
-
{
-
int intStart = -1, intEnd = -1;
-
string strRequest = "", strPage = "",strFile = "", strResponse = "";
-
-
// Set the TcpListener on port 11000.
-
Int32 port = 11000;
-
IPAddress localAddr = IPAddress.Parse("127.0.0.1");
-
-
// TcpListener server = new TcpListener(port);
-
server = new TcpListener(localAddr, port);
-
-
// Start listening for client requests.
-
server.Start();
-
-
// Buffer for reading data
-
Byte[] bytes = new Byte[256];
-
String data = null;
-
-
// Enter the listening loop.
-
while (true)
-
{
-
Console.Write("Waiting for a connection... \n");
-
-
try
-
{
-
-
-
// Perform a blocking call to accept requests.
-
// You could also user server.AcceptSocket() here.
-
TcpClient client = server.AcceptTcpClient();
-
Console.WriteLine("Client Connected from IP Address" + client.Client.AddressFamily.ToString());
-
-
data = null;
-
-
// Get a stream object for reading and writing
-
NetworkStream stream = client.GetStream();
-
-
int i;
-
-
// Loop to receive all the data sent by the client.
-
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
-
{
-
// Translate data bytes to a ASCII string.
-
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
-
Console.WriteLine("Received: {0}", data);
-
-
// Figure Out What the client wants
-
intStart = data.IndexOf("GET");
-
intEnd = data.IndexOf("\r\n");
-
strRequest = data.Substring(intStart, intEnd);
-
-
intStart = data.IndexOf(" ") + 1;
-
intEnd = data.IndexOf(" ", intStart);
-
strRequest = strRequest.Substring(intStart, intEnd - intStart);
-
-
-
if (strRequest == "/")
-
{
-
// Request is the Home page
-
strPage = "index.html";
-
}
-
else
-
{
-
// Request is a specific page
-
strPage = strRequest.Substring(1);
-
}
-
-
// We have the page the browser is requesting
-
Console.WriteLine("Page Requested: " + strPage);
-
-
//strResponse = "<html><body><h1>Hello World!</h1></body></html>";
-
-
-
strFile = GetFile(strPage);
-
-
strResponse = "HTTP/1.1 200 OK\n" +
-
"Connection: close\n" +
-
"Date: " + System.DateTime.Now + "\n" +
-
"Server: Apache/2.2.3 (CentOS)\n" +
-
"Last-Modified: Tue, 09 Aug 2011 15:11:03 GMT\n" +
-
"Content-Length: " + Convert.ToString(strFile.Length) + "\n" +
-
"Content-Type: text/html\n\n" +
-
"Content-Type: image/jpg\n\n" +
-
strFile;
-
-
// Convert String back into BYTE array.
-
byte[] msg = System.Text.Encoding.ASCII.GetBytes(strResponse);
-
-
// Send back a response.
-
stream.Write(msg, 0, msg.Length);
-
Console.WriteLine("Sent: {0}", data);
-
}
-
-
// Shutdown and end connection
-
client.Close();
-
-
-
}
-
catch
-
{
-
-
}
-
}
-
}
-
catch (SocketException e)
-
{
-
Console.WriteLine("SocketException: {0}", e);
-
}
-
finally
-
{
-
// Stop listening for new clients.
-
server.Stop();
-
}
-
-
-
Console.WriteLine("\nHit enter to continue...");
-
Console.Read();
-
}
-
-
public static string GetFile(String strFileName)
-
{
-
string strPath = "";
-
string strResult = "";
-
-
if (!File.Exists(strFileName))
-
{
-
// Warning message that file does not exist
-
strResult = "404 - File does not exist";
-
}
-
else
-
{
-
strResult = File.ReadAllText(strFileName);
-
}
-
-
return strResult;
-
}
-
}
-
Can I get some help with what lines I need to add to the headers or whatever to get my images to show when I log into the program?
Thanks In Advance!!
0 1144 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: MrDom |
last post by:
I am wondering if someone can help solve this question I have a table
in sql server 2000, I setup it using Enterprise manager.
When I generate an SQL Script for this table it scripts as:
CREATE TABLE . (
IDENTITY (1, 1) NOT NULL ,
(255) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL
|
by: milkyway |
last post by:
Hello everyone,
I have a few values and variables that I want to post to a server
(without using a SUBMIT button). Is there a way to post data from
within javascript - do sockets or connections have to be open for this
to work?
Any help, hints or advice is appreciated :-)
Kindest Regards.
|
by: ernst |
last post by:
Hello,
I cannot get ASP.NET running with a simple testfile
called "test.aspx". It contains the following lines:
<html>
<head>
<script language="vb" runat="server">
sub page_load()
meinLabel.text = "Hallo ASP.net Server funktioniert"
end sub
|
by: Bruce Russell |
last post by:
This may sound stupid but I can't rename the WebForm1.aspx in the
solution explorer.
The file is located in my local web server at
C:\Inetpub\wwwroot\Lab3-VB-Starter\WebForm1.aspx
Is there some configuration problem in my IIS setup?
Thanks,
|
by: Pål Johansen |
last post by:
I made a program that does screen scraping from a website, but when running
this progran on a Win 2003 server the httpwebrequest works fine for a while
but suddenly never returns from the request (and doesn't time out either)
and I have to restart the program. It works fine on a winxp machine.
**********************************************************
Sub Download_WebPage()
Dim strPost As String
Dim Lines As String
Dim DownloadOk As...
| |
by: Oenone |
last post by:
I am developing an assembly that can be used either by a Windows Forms
application or from within an ASP.NET web site.
When running within the Forms app, I can break into the code while it is
running and use edit-and-continue to modify the sourcecode and then
immediately execute the modifications.
When running within the web site, the source-code is all read-only when I
break into it. The little padlock icon appears in the tab for each...
|
by: abcd |
last post by:
I have Page1.asp which is posted to Page2.asp.
Page2.asp runs in hidden frame. When web server is running and Page2.asp is
running I can pass suceess / fail / any error messages to Page1.asp using
javascript.
Now if Web server is down then Pag1.asp progress bar is running continuously
and have no idea whats going on whethere there is logic error or error due
to web server down.
How to handle this smartly and propogate an error to...
|
by: Dan Fulbright |
last post by:
I'm trying to install PHP 5.2.2 on Windows, but I keep getting errors
when running go-pear.bat:
mmap cache can't open phar://go-pear.phar/index.php
mmap cache can't open phar://go-pear.phar/PEAR/Start/CLI.php
mmap cache can't open phar://go-pear.phar/PEAR/Start.php
There are 20 of these lines. After continuing through the script, it
dies with this error:
|
by: Anna97 |
last post by:
Hi,
I guess I've built my site sort of strangely:
The images are in the html (using tables), but the text is all in css positioned using coordinates (hovering over the images). I need my page to be centered. However, after I center it, the html images move when the browser is resized. My text is sticking to it's coordinates. How do I get the images to stay where they are, as well.
Any help is much appreciated.
Thank you,
|
by: handique |
last post by:
Hi,
I have javascript code for rotating images, but the rotation starts only when mouse is placed over the image. But i want to rotate images automatically when the page loads. Can any guide me in this regard.
the javscript for rotating images is :
mg src="'+mImages.src+'" onmouseover="this.src=\''+mImagesO.src+'\'" onmouseout="this.src=\''+mImages.src+'\'" border=0 id="img'+this.a3+'" style="cursor:pointer
I want to replace...
|
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: 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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |