113 lines
4.2 KiB
VB.net
113 lines
4.2 KiB
VB.net
|
Imports System.Threading
|
|||
|
Imports System.Net
|
|||
|
Public Class main
|
|||
|
Dim weblistener As HttpListener
|
|||
|
|
|||
|
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles StartButton.Click
|
|||
|
If Not weblistener Is Nothing Then
|
|||
|
weblistener.Abort()
|
|||
|
weblistener = Nothing
|
|||
|
log("Stopped")
|
|||
|
StartButton.BackColor = Color.Lime
|
|||
|
StartButton.Text = "Start"
|
|||
|
Else
|
|||
|
weblistener = New HttpListener
|
|||
|
weblistener.Prefixes.Add("http://+:8080/")
|
|||
|
weblistener.Start()
|
|||
|
Dim listenthread As New Thread(AddressOf listenforconnection)
|
|||
|
listenthread.Start()
|
|||
|
log("Started")
|
|||
|
StartButton.BackColor = Color.Red
|
|||
|
StartButton.Text = "Stop"
|
|||
|
End If
|
|||
|
|
|||
|
End Sub
|
|||
|
|
|||
|
Public Sub listenforconnection()
|
|||
|
Dim context As HttpListenerContext
|
|||
|
Dim resp As HttpListenerResponse
|
|||
|
Dim lastpos As New Point(0, 0)
|
|||
|
Dim startpos As New Point(0, 0)
|
|||
|
Dim lastpacket As Long = -1
|
|||
|
While weblistener.IsListening
|
|||
|
Try
|
|||
|
context = weblistener.GetContext()
|
|||
|
Catch ex As Exception
|
|||
|
If weblistener Is Nothing OrElse weblistener.IsListening = False Then
|
|||
|
Exit Sub
|
|||
|
End If
|
|||
|
End Try
|
|||
|
resp = context.Response
|
|||
|
Dim path As String = context.Request.Url.AbsolutePath
|
|||
|
log(context.Request.RemoteEndPoint.ToString & " " & path)
|
|||
|
|
|||
|
' check for valid command packets
|
|||
|
|
|||
|
If path = "/" Then
|
|||
|
Dim mainpagebytes As Byte() = FileIO.FileSystem.ReadAllBytes("page.html")
|
|||
|
resp.OutputStream.Write(mainpagebytes, 0, mainpagebytes.Length)
|
|||
|
resp.Close()
|
|||
|
lastpacket = 0
|
|||
|
Continue While
|
|||
|
|
|||
|
ElseIf path.StartsWith("/move/") Then
|
|||
|
Dim x As Integer = path.Split("/")(2)
|
|||
|
Dim y As Integer = path.Split("/")(3)
|
|||
|
Dim pack As Long = path.Split("/")(4)
|
|||
|
If pack > lastpacket Then
|
|||
|
movemouse(x - lastpos.X, y - lastpos.Y)
|
|||
|
lastpos.X = x
|
|||
|
lastpos.Y = y
|
|||
|
lastpacket = pack
|
|||
|
End If
|
|||
|
|
|||
|
ElseIf path.StartsWith("/start/") Then
|
|||
|
Dim x As Integer = path.Split("/")(2)
|
|||
|
Dim y As Integer = path.Split("/")(3)
|
|||
|
Dim pack As Long = path.Split("/")(4)
|
|||
|
If pack > lastpacket Then
|
|||
|
lastpos.X = x
|
|||
|
lastpos.Y = y
|
|||
|
startpos.X = x
|
|||
|
startpos.Y = y
|
|||
|
lastpacket = pack
|
|||
|
End If
|
|||
|
|
|||
|
ElseIf path.StartsWith("/end/") Then
|
|||
|
Dim x As Integer = path.Split("/")(2)
|
|||
|
Dim y As Integer = path.Split("/")(3)
|
|||
|
Dim pack As Long = path.Split("/")(4)
|
|||
|
If pack > lastpacket Then
|
|||
|
Dim tol As Integer = TapInput.Value
|
|||
|
If (Math.Abs(x - startpos.X) < tol) And (Math.Abs(y - startpos.Y) < tol) Then
|
|||
|
leftclick()
|
|||
|
End If
|
|||
|
lastpacket = pack
|
|||
|
End If
|
|||
|
End If
|
|||
|
|
|||
|
Dim respstr As String = "ok"
|
|||
|
Dim respbytes As Byte() = System.Text.Encoding.UTF8.GetBytes(respstr)
|
|||
|
resp.OutputStream.Write(respbytes, 0, respbytes.Length)
|
|||
|
resp.Close()
|
|||
|
|
|||
|
End While
|
|||
|
End Sub
|
|||
|
|
|||
|
Private Sub Form1_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
|
|||
|
If Not weblistener Is Nothing Then
|
|||
|
weblistener.Abort()
|
|||
|
End If
|
|||
|
End Sub
|
|||
|
|
|||
|
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
|
|||
|
Control.CheckForIllegalCrossThreadCalls = False
|
|||
|
Button1_Click(sender, e)
|
|||
|
End Sub
|
|||
|
Private Sub log(str As String)
|
|||
|
LogText.Text = Now.ToString("[HH:mm:ss.fff] ") & str & vbNewLine & LogText.Text
|
|||
|
End Sub
|
|||
|
|
|||
|
|
|||
|
End Class
|