home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / An_easy_HT2021449232006.psc / Form1.frm < prev    next >
Text File  |  2006-09-23  |  6KB  |  177 lines

  1. VERSION 5.00
  2. Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
  3. Begin VB.Form FrmMain 
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "Michael Billington's HTTP daemon."
  6.    ClientHeight    =   4080
  7.    ClientLeft      =   45
  8.    ClientTop       =   435
  9.    ClientWidth     =   6165
  10.    Icon            =   "Form1.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   272
  15.    ScaleMode       =   3  'Pixel
  16.    ScaleWidth      =   411
  17.    StartUpPosition =   3  'Windows Default
  18.    Begin VB.Timer Timer1 
  19.       Interval        =   1000
  20.       Left            =   480
  21.       Top             =   0
  22.    End
  23.    Begin MSWinsockLib.Winsock socket 
  24.       Index           =   0
  25.       Left            =   0
  26.       Top             =   0
  27.       _ExtentX        =   741
  28.       _ExtentY        =   741
  29.       _Version        =   393216
  30.    End
  31.    Begin VB.PictureBox Pic 
  32.       AutoRedraw      =   -1  'True
  33.       BackColor       =   &H00FFFFFF&
  34.       BorderStyle     =   0  'None
  35.       BeginProperty Font 
  36.          Name            =   "Courier New"
  37.          Size            =   8.25
  38.          Charset         =   0
  39.          Weight          =   400
  40.          Underline       =   0   'False
  41.          Italic          =   0   'False
  42.          Strikethrough   =   0   'False
  43.       EndProperty
  44.       Height          =   3855
  45.       Left            =   0
  46.       ScaleHeight     =   257
  47.       ScaleMode       =   3  'Pixel
  48.       ScaleWidth      =   409
  49.       TabIndex        =   0
  50.       Top             =   0
  51.       Width           =   6135
  52.    End
  53.    Begin VB.Label Label5 
  54.       Caption         =   "0"
  55.       Height          =   255
  56.       Left            =   5400
  57.       TabIndex        =   5
  58.       Top             =   3840
  59.       Width           =   735
  60.    End
  61.    Begin VB.Label Label4 
  62.       Caption         =   "Clients since last restart:"
  63.       Height          =   255
  64.       Left            =   3600
  65.       TabIndex        =   4
  66.       Top             =   3840
  67.       Width           =   2655
  68.    End
  69.    Begin VB.Label Label3 
  70.       Caption         =   "Time since last restart:"
  71.       Height          =   255
  72.       Left            =   0
  73.       TabIndex        =   3
  74.       Top             =   3840
  75.       Width           =   1695
  76.    End
  77.    Begin VB.Label Label2 
  78.       Caption         =   "(reset at 300)"
  79.       Height          =   255
  80.       Left            =   2040
  81.       TabIndex        =   2
  82.       Top             =   3840
  83.       Width           =   1095
  84.    End
  85.    Begin VB.Label Label1 
  86.       Caption         =   "0"
  87.       Height          =   255
  88.       Left            =   1680
  89.       TabIndex        =   1
  90.       Top             =   3840
  91.       Width           =   495
  92.    End
  93. End
  94. Attribute VB_Name = "FrmMain"
  95. Attribute VB_GlobalNameSpace = False
  96. Attribute VB_Creatable = False
  97. Attribute VB_PredeclaredId = True
  98. Attribute VB_Exposed = False
  99. '//Code by michael Billington. This work is in the public domain, do with it as you wish
  100. Option Explicit
  101. Const Serverport = 80 '//Standard HTTP port, change to whatever you like
  102.  
  103. Private Sub Form_Load()
  104. Outp "Computer connected to network on port " & Serverport, 9
  105. Outp "Your network IP address is " & socket(0).LocalIP, 9
  106. socket(0).Bind Serverport
  107. socket(0).Listen
  108. End Sub
  109.  
  110. Private Sub Form_Unload(Cancel As Integer)
  111. End
  112. End Sub
  113.  
  114. Private Sub socket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
  115. Outp socket(Index).RemoteHost & socket(Index).RemoteHostIP & " now connected", 9
  116. socket(Index).Close
  117. socket(Index).Accept requestID
  118. Load socket(Index + 1)
  119. socket(Index + 1).Bind Serverport
  120. socket(Index + 1).Listen
  121. End Sub
  122.  
  123. Private Sub socket_DataArrival(Index As Integer, ByVal bytesTotal As Long)
  124. Dim str As String
  125. socket(Index).GetData str
  126. Outp socket(Index).RemoteHostIP & ":" & getL(str, vbCrLf), 8
  127. Dim temp As String
  128. temp = getL(getR(str, " "), " ")
  129. temp = Replace(temp, "/", "\")
  130. If temp = "\" Then temp = "\index.htm"
  131. temp = Replace(temp, "%20", " ")
  132. Dim FileContent As String
  133. If FileExists(App.Path & "\files" & temp) Then
  134.   FileContent = LoadText(App.Path & "\files" & temp)
  135.   Select Case getRrev(temp, ".")
  136.     Case "txt": socket(Index).SendData ReturnFile(FileContent, "text/plain")
  137.     Case "htm": socket(Index).SendData ReturnFile(FileContent, "text/html")
  138.     Case "html": socket(Index).SendData ReturnFile(FileContent, "text/html")
  139.     Case "png": socket(Index).SendData ReturnFile(FileContent, "image/png")
  140.     Case "zip": socket(Index).SendData ReturnFile(FileContent, "application/zip")
  141.     Case Else: socket(Index).SendData ReturnFile(FileContent, "application/zip")
  142.   End Select
  143. Else
  144.   socket(Index).SendData Return404(LoadText(App.Path & "\files\404.htm"))
  145. End If
  146. End Sub
  147.  
  148. Function ReturnFile(doc As String, filetype As String) As String
  149. ReturnFile = "HTTP/1.1 200 OK" & vbCrLf & "Content-Type: " & filetype & vbCrLf & "Content-Length: " & Len(doc) & vbCrLf & vbCrLf & doc & vbCrLf & vbCrLf & vbCrLf
  150. End Function
  151. Function Return404(doc As String) As String
  152. Return404 = "HTTP/1.1 404 NOT FOUND" & vbCrLf & "Content-Type: text/html" & vbCrLf & "Content-Length: " & Len(doc) & vbCrLf & vbCrLf & doc & vbCrLf & vbCrLf & vbCrLf
  153. End Function
  154.  
  155. Private Sub socket_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  156. Outp Number & " " & Description
  157. End Sub
  158.  
  159. Private Sub Timer1_Timer()
  160. Label1.Caption = Val(Label1.Caption) + 1
  161. If Label1.Caption >= 300 Then server_reset: Label1.Caption = "0"
  162. Label5.Caption = socket.ubound
  163. End Sub
  164.  
  165. Sub server_reset()
  166.   Dim i As Long
  167.   If socket.ubound <> 0 Then
  168.     Outp "Resetting server... " & socket.ubound & " clients", 9
  169.       For i = 1 To socket.ubound
  170.       socket(i).Close
  171.       Unload socket(i)
  172.       Next i
  173.     socket(0).Close
  174.     socket(0).Listen
  175.   End If
  176. End Sub
  177.