All Answers

All Answers » Re: 2 way comms between multiple clients & web app » Comments for "Re: 2 way comms between multiple clients & web app"
  • Darren
    Luca, the clients are standard desktop apps not wisej desktop apps. For test purposes I am using a webclient to POST info to the wisej web app. The wisej web app gets this post in the handler, so client to web app comms is ok, but I don’t understand how web app sends back posts to client. What method should be used? Thanks
  • Darren
    I.e. your comment “Then the server can send requests back to the ip address of the clients”… is what I can’t fathom out. Clients are standard desktop apps. How does web app send the request to standard desktop app?
  • Darren
    Folks, Any pointers on this? How should the web app. communicate back to the desktop apps? TCP? HTTP? Any help appreciated! Thank you
  • Luca (ITG)
    See my answer above + the desktop app can listen to web requests easily using an HttpListener. https://msdn.microsoft.com/en-us/library/system.net.httplistener(v=vs.110).aspx (there are several examples on codeproject or stackoverflow)
  • Darren
    Luca, My issue is understanding how the web app. sends a request to the desktop app. (at any time). I have since found that when a handler receives a request, you can send back an immediate response to the client with Context.Response.Write(string) from within the Processrequest function. However, what I can’t figure out is how the web app. can send a Response.Write(string) at any time I want (other than from within Processrequest). I’d like to implement a polling scheme, where the web app. polls each client in turn for their data. To do this, I need to know how the web app. makes the request to the clients?
  • Luca (ITG)
    Using the WebRequest or WebClient class. It simply needs to make a plain URL request and read the response.
  • Darren
    Ahhh, OK. I had a hunch that was the case but wasn’t sure. I’m trying to find other, similar scenarios on the web but I can’t. It almost seems I’m doing something unique. Maybe I’m not looking in the right places. I’m also struggling with picking the right comms. method. It now seems I can use a webclient at both ends, but why would I choose this over, say, a TCP channel. I could also use Modbus TCP, for example. It “feels” like I should use webclient because it keeps everything “web”, but this is not necessarily the correct or best way. I don’t know. In any case, I’m pretty certain a polling method (once all clients have made an initial connection/registration) is the best method of data transfer because it has the obvious benefit of the web app. being in control of the system, rather than multiple clients randomly sending continuous data and hoping the web app. captures it all. I imagine all comms. will need to async.
  • Darren
    Luca, Sorry, I’m unsure how to read the client ip address using Application.UserHostAddress. I will need to register the client within the handler, I assume. “Application” is a type. Can’t I get the client ip address from the request (context) in the handler?
  • Darren
    I need to add that I will want to get the client IP (and computer name, if possible) via both IIS and stand-alone hosting.
  • Darren
    Perhaps the client needs to send it’s IP in the initial registration request?