1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| Imports System.Net
Imports System.Threading
Imports System.IO
Public Class ServeurHTTP
Private hl As HttpListener
Dim listenForNextRequest As AutoResetEvent = New AutoResetEvent(False)
Public Sub Start()
hl = New HttpListener()
hl.Prefixes.Add("http://*:5500/")
hl.IgnoreWriteExceptions = True
hl.Start()
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf ListenHTTP))
End Sub
Private Sub ListenHTTP(state As Object)
While (hl.IsListening)
hl.BeginGetContext(New AsyncCallback(AddressOf ListenerCallback), hl)
listenForNextRequest.WaitOne()
End While
End Sub
'************************************************************************************************
''' <summary>
''' Manage request and answer to client
''' </summary>
''' <param name="ar"></param>
'''
Private Sub ListenerCallback(ar As IAsyncResult)
' Get request
Dim listener As HttpListener = ar.AsyncState
Dim context As System.Net.HttpListenerContext = Nothing
If (listener Is Nothing) Then Return
Try
context = listener.EndGetContext(ar)
Catch
Return
Finally
listenForNextRequest.Set()
End Try
' Route request
Dim Result As String = ""
Dim route As String = context.Request.Url.LocalPath.ToString()
MainForm.BeginInvoke(New MainForm.d_MajRTB(AddressOf MainForm.MajRTB), "test") ' <------ ICI |
Partager