Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/freehos1/public_html/projectus/core/open_close_dbase_connection.php on line 0

Deprecated: Function split() is deprecated in /home/freehos1/public_html/projectus/A-Simple-Server/index.php(0) : eval()'d code on line 22

Deprecated: Function split() is deprecated in /home/freehos1/public_html/projectus/A-Simple-Server/index.php(0) : eval()'d code on line 35

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/freehos1/public_html/projectus/scripts/get_ad_type_position.php on line 0

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/freehos1/public_html/projectus/scripts/load_ads.php on line 0

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/freehos1/public_html/projectus/scripts/sponsor_found.php on line 0

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/freehos1/public_html/projectus/scripts/load_links.php on line 0

Deprecated: Function split() is deprecated in /home/freehos1/public_html/projectus/A-Simple-Server/index.php(0) : eval()'d code on line 161

Deprecated: Function split() is deprecated in /home/freehos1/public_html/projectus/A-Simple-Server/index.php(0) : eval()'d code on line 164

Deprecated: Function split() is deprecated in /home/freehos1/public_html/projectus/A-Simple-Server/index.php(0) : eval()'d code on line 167
visual basic dot net code for dynamic webserver
projectus.freehost7.com:UG and PG level projects,mini projects and many more here ...



Visual basic dot net code (VB.NET code) for web server

a.Create Test Web Server Application

'---------------------------------------------------------------------------------

 

'------------------------------------------------------------------------------------

Public Class ROOT

'quick and dirty proggy to show how it works

Private server As CassiniVB.Server

Private _Port As Integer = 8088

Public Property Port() As Integer

Get

Return _Port

End Get

Set(ByVal value As Integer)

_Port = value

End Set

End Property

Private _virtRoot As String = "/"

Public Property VirtRoot() As String

Get

Return _virtRoot

End Get

Set(ByVal value As String)

_virtRoot = value

End Set

End Property

Private _appPath As String = "C:\"

Public Property AppPath() As String

Get

Return _appPath

End Get

Set(ByVal value As String)

_appPath = value

End Set

End Property

Private Sub BtnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStart.Click

'Port = 8088

'AppPath = "C:\PathToWebProject"

'VirtRoot = "/"

Try

'just point app path to your ASP.Net website or webservice

StopServer()

server = New CassiniVB.Server(Port, VirtRoot, AppPath)

server.Start()

Me.LinkLabel1.Text = server.RootUrl

Me.LinkLabel1.Visible = True

Catch ex As Exception

MessageBox.Show(ex.ToString, "~error", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try

End Sub

Private Sub StopServer()

If server IsNot Nothing Then

server.Stop()

server = Nothing

Me.LinkLabel1.Visible = False

End If

End Sub

Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click

StopServer()

End Sub

Private Sub tbxPort_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles tbxPort.Validating

If Not IsNumeric(Me.tbxPort.Text) Then

MessageBox.Show("Enter port number")

e.Cancel = True

Else

Integer.TryParse(Me.tbxPort.Text, Port)

End If

End Sub

Private Sub tbxAppPath_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles tbxAppPath.Validating

If Not My.Computer.FileSystem.DirectoryExists(Me.tbxAppPath.Text) Then

MessageBox.Show("path not found")

e.Cancel = True

End If

AppPath = Me.tbxAppPath.Text

End Sub

Private Sub tbxVirtPath_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles tbxVirtPath.Validating

Me.VirtRoot = Me.tbxVirtPath.Text

End Sub

Private Sub LinkLabel1_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles LinkLabel1.MouseClick

Process.Start(LinkLabel1.Text)

End Sub

End Class

b. Create application Server dll

**********************************************************************************

'------------------------------------------------------------------------------------

Imports System

Imports System.Collections.Generic

Imports System.Globalization

Imports System.IO

Imports System.Net

Imports System.Net.Sockets

Imports System.Reflection

Imports System.Runtime.InteropServices

Imports System.Runtime.Remoting

Imports System.Threading

Imports System.Web

Imports System.Web.Hosting

Public Class Server

Inherits MarshalByRefObject

Private _port As Integer

Private _virtualPath As String

Private _physicalPath As String

Private _shutdownInProgress As Boolean

Private _socket As Socket

Private _host As Host

Public Sub New(ByVal port As Integer, ByVal virtualPath As String, ByVal physicalPath As String)

_port = port

_virtualPath = virtualPath

_physicalPath = If(physicalPath.EndsWith("\", StringComparison.Ordinal), physicalPath, physicalPath & "\")

End Sub

Public Overloads Overrides Function InitializeLifetimeService() As Object

' never expire the license

Return Nothing

End Function

Public ReadOnly Property VirtualPath() As String

Get

Return _virtualPath

End Get

End Property

Public ReadOnly Property PhysicalPath() As String

Get

Return _physicalPath

End Get

End Property

Public Property Port() As Integer

Get

Return _port

End Get

Private Set(ByVal value As Integer)

_port = value

End Set

End Property

Public ReadOnly Property RootUrl() As String

Get

If _port <> 80 Then

Return ("http://localhost:" & _port) + _virtualPath

Else

Return "http://localhost" & _virtualPath

End If

End Get

End Property

Private Function CreateSocketBindAndListen(ByVal family As AddressFamily, ByVal address As IPAddress) As Socket

Dim socket = New Socket(family, SocketType.Stream, ProtocolType.Tcp)

socket.Bind(New IPEndPoint(address, port))

socket.Listen(CInt(SocketOptionName.MaxConnections))

Return socket

End Function

Public Sub Start()

Try

_socket = CreateSocketBindAndListen(AddressFamily.InterNetwork, IPAddress.Loopback)

Catch ex As Exception

_socket = CreateSocketBindAndListen(AddressFamily.InterNetworkV6, IPAddress.IPv6Loopback)

End Try

ThreadPool.QueueUserWorkItem(AddressOf StartWork)

End Sub

Private Sub StartWork(ByVal state As Object)

While Not _shutdownInProgress

Try

Dim acceptedSocket As Socket = _socket.Accept

ThreadPool.QueueUserWorkItem(AddressOf ProcessSocket, acceptedSocket)

Catch ex As Exception

Thread.Sleep(50)

End Try

End While

End Sub

Private Sub ProcessSocket(ByVal state As Object)

Dim AcceptedSocket As Socket = DirectCast(state, Socket)

If Not _shutdownInProgress Then

Dim conn = New Connection(Me, AcceptedSocket)

' wait for at least some input

If conn.WaitForRequestBytes() = 0 Then

conn.WriteErrorAndClose(400)

Else

' find or create host

Dim host = GetHost()

If host Is Nothing Then

conn.WriteErrorAndClose(500)

Else

' process request in worker app domain

host.ProcessRequest(conn)

End If

End If

End If

End Sub

Public Sub [Stop]()

_shutdownInProgress = True

Try

If _socket IsNot Nothing Then

_socket.Close()

End If

Catch

Finally

_socket = Nothing

End Try

Try

If _host IsNot Nothing Then

_host.Shutdown()

End If

While _host IsNot Nothing

Thread.Sleep(100)

End While

Catch

Finally

_host = Nothing

End Try

End Sub

' called at the end of request processing

' to disconnect the remoting proxy for Connection object

' and allow GC to pick it up

Public Sub OnRequestEnd(ByVal conn As Connection)

RemotingServices.Disconnect(conn)

End Sub

Public Sub HostStopped()

_host = Nothing

End Sub

Private Function GetHost() As Host

If _shutdownInProgress Then

Return Nothing

End If

Dim host As Host = _host

If host Is Nothing Then

SyncLock Me

host = _host

If host Is Nothing Then

host = DirectCast(CreateWorkerAppDomainWithHost(_virtualPath, _physicalPath, GetType(Host)), Host)

host.Configure(Me, _port, _virtualPath, _physicalPath)

_host = host

End If

End SyncLock

End If

Return host

End Function

Private Shared Function CreateWorkerAppDomainWithHost(ByVal virtualPath As String, ByVal physicalPath As String, ByVal hostType As Type) As Object

' this creates worker app domain in a way that host doesn't need to be in GAC or bin

' using BuildManagerHost via private reflection

Dim uniqueAppString As String = String.Concat(virtualPath, physicalPath).ToLowerInvariant()

Dim appId As String = (uniqueAppString.GetHashCode()).ToString("x", CultureInfo.InvariantCulture)

' create BuildManagerHost in the worker app domain

Dim appManager = ApplicationManager.GetApplicationManager()

Dim buildManagerHostType = GetType(HttpRuntime).Assembly.[GetType]("System.Web.Compilation.BuildManagerHost")

Dim buildManagerHost = appManager.CreateObject(appId, buildManagerHostType, virtualPath, physicalPath, False)

' call BuildManagerHost.RegisterAssembly to make Host type loadable in the worker app domain

buildManagerHostType.InvokeMember("RegisterAssembly", BindingFlags.Instance Or BindingFlags.InvokeMethod Or BindingFlags.NonPublic, Nothing, buildManagerHost, New Object(1) {hostType.Assembly.FullName, hostType.Assembly.Location})

' create Host in the worker app domain

Return appManager.CreateObject(appId, hostType, virtualPath, physicalPath, False)

End Function

End Class