0

At the moment I'm writing a small program in C# for windows 7 which can send notifications over GCM (Google Cloud Messeging) to my Android smartphone. For this I send some data via POST to my WebServer which then pushes the data over GCM to my smartphone. That works great in this way but I also want to send some data to my program from my Smartphone.

My problem now is that I do not know how I can notificy my C# program from my WebServer. I thought about something like this:

Smartphone -> send Data to WebServer -> notify C# program

I do not want to use polling and the GCM client is only for android smartphones. So what do you think is the best way to notify my program that some data is avaible for it? I read something about HTTP streaming but I do not know how it works and have no idea if I can implement it with C#. Or do you have other ideas how I can solve this problem?

Cilenco
  • 6,951
  • 17
  • 72
  • 152

1 Answers1

1

SignalR is a good shout but you should also understand the base concepts of socket programming. C# makes it really easy to open a socket and listen for messages. The Microsoft website shows you how to handle a requests synchronously here.

Http is just a message protocol. Once you understand the protocol reading the messages is not too hard. Remember if you are receiving messages from the server it will need to know your IP address etc.

Luthervd
  • 1,388
  • 2
  • 14
  • 25
  • Thank you for this that looks really really good. But I have one more question: You said the server needs to know my IP etc. If I send a request to the server from my program the server knows my IP adress and so on right? So let's say my program "registers" itself (send a request to the server) on the start then I can store the information on the server and use them later if I want to communicate with the program from the server right? And do I have to open some more ports on my router to get this work? – Cilenco Apr 03 '15 at 17:13
  • Yes you could register the IP on the server. Make sure you are thinking security etc etc. Also reconsider the polling. If your http data is light then it might be fine to poll every 30 seconds or so. Web browsers work well sending loads of requests and web servers were designed to handle these loads. It would make your life a whole lot easier and secure as you aren't storing the machines contact details permanently on the server. – Luthervd Apr 03 '15 at 17:19