Web Server with out IIS

thirteentwenty

Well-known member
Joined
Oct 9, 2008
Messages
80
Location
Honolulu
Programming Experience
Beginner
OK, so I'm jumping around a bit with what I'm learning but there is a method to my madness... I promise :D

Anyways, I've use this app for a while now, a bit of freeware, that opens up a little webserver like thing, I've found out how to edit the html file so display what I wish but I'm kind of tired of doing that...

I've been googling around and havent really found anything about uisng VBs remoting to allow http traffic, I found a bit of good code here that does it via tcp (sorry i cant remember whos it was), but that requires a client side app, I'm looking to view it through a browser. I found this post pointing to a .net remoting tutorial, but again its not quite what I'm looking for... I've tried MSDN but it always seems to point me back to .net 1.1 stuff (maybe it still works I'm not sure)...

So to you, the fine people of this fine forum, I ask, can someone, or a bunch of someones please either a) Link me to someplace that will give me a hand with learning this, or b) provide me with some hints like namespaces or bits of code that I can use to get started and hit up msdn for more info...

Gosh, I hope I posted this in the right area...

Thank you for your time =)
 
hmm i didn't get your point completely
but i put some namespaces for you here to google them , its all about .NET sockets - remoting - Web & html & other stuffs
system.web ( ability to download pages content into a string )
system.net
if you want to run your own http server , u need to implement a TCP server,
also every http server has a root path to place the http files , like inetpub/wwwroots/
also a port is require , commonly it will be set on 80, so if there is another program that is using of this Port ( like iis or apache ) u have to stop it.
there is some code that u can use it as thread running , also contain Lock , that doesn't let to two web page requires to come in & prevent of any kind of messing up .
VB.NET:
Public Sub listenerThread()
    Dim port As Integer = 0
    port = Convert.ToInt16(tbPort.Text)
    Dim tcpListener As New TcpListener(port)
    tcpListener.Start()
    While True
        Dim handlerSocket As Socket = tcpListener.AcceptSocket()
        If handlerSocket.Connected Then
            lbConnections.Items.Add(handlerSocket.RemoteEndPoint.ToString() & " connected.")
            SyncLock Me
                alSockets.Add(handlerSocket)
                Dim thdstHandler As New ThreadStart(handlerThread)
                Dim thdHandler As New Thread(thdstHandler)
                thdHandler.Start()
            End SyncLock
        End If
    End While
End Sub
VB.NET:
Public Sub handlerThread()
    Dim handlerSocket As Socket = DirectCast(alSockets(alSockets.Count - 1), Socket)
    Dim streamData As String = ""
    Dim filename As String = ""
    Dim verbs As String()
    Dim quickRead As StreamReader
    Dim networkStream As New NetworkStream(handlerSocket)
    quickRead = New StreamReader(networkStream)
    streamData = quickRead.ReadLine()
    verbs = streamData.Split(" ".ToCharArray())
    ' Assume verbs[0]=GET
    filename = verbs(1).Replace("/", "\")
    If filename.IndexOf("?") <> -1 Then
        ' Trim of anything after a question mark (Querystring)
        filename = filename.Substring(0, filename.IndexOf("?"))
    End If
    If filename.EndsWith("\") Then
        ' Add a default page if not specified
        filename += "index.htm"
    End If
    filename = tbPath.Text + filename
    Dim fs As New FileStream(filename, FileMode.OpenOrCreate)
    fs.Seek(0, SeekOrigin.Begin)
    Dim fileContents As Byte() = New Byte(fs.Length - 1) {}
    fs.Read(fileContents, 0, CInt(fs.Length))
    fs.Close()
    ' optional: modify fileContents to include HTTP header.
    handlerSocket.Send(fileContents)
    lbConnections.Items.Add(filename)
    handlerSocket.Close()
End Sub
also start this thread in a button click event:
VB.NET:
Private Sub btnStart_Click(ByVal sender As Object, ByVal e As System.EventArgs)
* * alSockets = New ArrayList()
* * Dim thdListener As New Thread(New ThreadStart(listenerThread))
* * thdListener.Start()
End Sub
u can implement you own http web server
have a good day
 
Great!!... Namemsapaces, that's probably what I was missing... I'll give your code a double look over and let you know how it goes... It may take me a while because I totally don't know what I'm doing :D and I'll be sure to post what I've done with it!

Thanks a million
 
Totally awesome mH_p0rtal... This is almost exactly what I was looking to do... Thank you very much... I've got much googling and much more learning to do

I did how ever run into a couple of errors, when with the below lines

VB.NET:
lbConnections.Items.Add(handlerSocket.RemoteEndPoint.ToString() & " connected.")

and

VB.NET:
lbConnections.Items.Add(filename)

Both about a non-valid cross thread...
Im sure I'll figure it out so no worries there.

The one other thing that I was worried about was closing... it leaves the 'server' open... but again I'll figure something to do with that too...

Thanks a million!!!
 
Back
Top