I am trying to create a webapp which is capable of reaching client side local resources.
I.e. I am going to install exe to client's computer. I want to fire this exe's function via JavaScript code (which is on the remote server) and fire a function that connects to a serial port, reads data and returns that data to a web page.
I can write C# or Visual Basic for client side app.
I was able to get some result via XMLHttpRequest so far. I opened port 9091 with C# and able to connect that port via writing localhost:9091 to browser's address bar and get data but I wasn't able to do it with JavaScript. (Getting CORS error)
Is it possible to accomplish this task with my skill set?
Example for client side app
Imports System.Net
Imports System.Globalization
Imports System.Collections.Specialized
Module HttpListener
Sub Main()
Dim prefixes(0) As String
prefixes(0) = "http://*:9091/"
ProcessRequests(prefixes)
End Sub
Private Sub ProcessRequests(ByVal prefixes() As String)
If Not System.Net.HttpListener.IsSupported Then
Console.WriteLine( _
"Windows XP SP2, Server 2003, or higher is required to " & _
"use the HttpListener class.")
Exit Sub
End If
' URI prefixes are required,
If prefixes Is Nothing OrElse prefixes.Length = 0 Then
Throw New ArgumentException("prefixes")
End If
' Create a listener and add the prefixes.
Dim listener As System.Net.HttpListener = _
New System.Net.HttpListener()
For Each s As String In prefixes
listener.Prefixes.Add(s)
Next
Try
' Start the listener to begin listening for requests.
listener.Start()
Console.WriteLine("Listening...")
' Set the number of requests this application will handle.
Dim numRequestsToBeHandled As Integer = 10
For i As Integer = 0 To numRequestsToBeHandled
Dim response As HttpListenerResponse = Nothing
Try
' Note: GetContext blocks while waiting for a request.
Dim context As HttpListenerContext = listener.GetContext()
' Create the response.
response = context.Response
Dim IncMessage As New NameValueCollection
IncMessage = context.Request.QueryString
Dim Field As String
Dim FValue As String
Dim Values() As String
For Each key As String In IncMessage.Keys
Values = IncMessage.GetValues(key)
Field = key
For Each value In Values
FValue = value
MsgBox(Field & " equals " & FValue)
Next value
Next key
Catch ex As HttpListenerException
Console.WriteLine(ex.Message)
Finally
If response IsNot Nothing Then
response.Close()
End If
End Try
Next
Catch ex As HttpListenerException
Console.WriteLine(ex.Message)
Finally
' Stop listening for requests.
listener.Close()
Console.WriteLine("Done Listening...")
End Try
End Sub
End Module
javascript code (which is in remote server)...unless you mean nodeJS then the Javascript runs in the browser, not the server. But in either case you cannot make a web app execute a local script. As others have said, this would be a total security disaster. There's a reason we don't have things like ActiveX any more!