1

I would like to implement a solution where I can pass data from my web page to a C# Application running on the same client PC that the browser is running on. After some research I found that using a TCP Listener or HTTP Listener, one can implement such a system - By making ajax requests/posts and then letting the listener catch these requests, then one can access the data in the request.

I then set out to write a small test application and hooray, it works! I used the code I found here(see answer) to implement a simple TCP listener, then opened my browser and navigated to http://localhost:8090/ and like I should, I saw the data that the listener responded with. This is great and all but now I have the problem that this listener needs to work along side my IIS server (or actually any service that will be hosting my wep app).

So I created a basic html page and added it as a site on IIS and tested it in the broweser to see if it works, so I simply navigated to http://localhost:8081/index.html and my test page showed up. That's good - Then I changed the port that the listener is listening to from 8090 to 8081, which is the port that IIS is using to host my site, and when I tried to start my listener with the new port I got the execption "An attempt was made to access a socket in a way forbidden by its access permissions". Is IIS causing this problem, or will what I'm trying to do not work in any case because I'm using it in the wrong context.

Another thing I would like to do is rather use a HTTP Listener, but the only HTTP Listener examples I can find is individuals using it to create simple HTTP servers that actually serves the html and other resources to the browser (e.g. here). All I want is a HTTP Listener implementation of the code mentioned previously in the thread I linked.

In Summary: Like I mentioned in my introduction ...implement a solution where I can pass data from my web page to a C# Application..., my end goal is to achieve communication to my C# app from my web page, doesn't matter if I use a HTTP or TCP Listener.

Community
  • 1
  • 1
Marnus Steyn
  • 1,053
  • 2
  • 16
  • 44
  • Only one application can listen on any given port at a time, i.e. the HTTP server and TCP servers need to be listening on distinct and separate ports, hence the error. You would send/receive data using normal AJAX on the client side, to http://localhost:8090/ - they don't need to be on the same port to communicate, just the same domain – jonny Mar 30 '16 at 13:33
  • As @JonathanBrooks mentioned the error is about port usage. Also if I understood you correctly you have a working example with a listener. So, you know how to pass variable to c#. – Orkun Bekar Mar 30 '16 at 13:44

1 Answers1

0

I found by solution here. By using a HTTP Listener and waiting for and handling ajax posts made to a specific url and port.

Marnus Steyn
  • 1,053
  • 2
  • 16
  • 44