Notify windows program from WebServer - c#

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?

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.

Related

Implementing phone communication with my C# application

I want to have the app i am creating to communicate with my personal android device. As in, my application will be monitoring something on my server, and when something changes it needs to somehow send an option to act or ignore to my phone, and my personal reply (Yes/No) should be send back to the server.
I don't mind any specific protocols. Anything which does not require an app running actively on my phone would be nice, but i am not that great with android native development so if it can be done it should be relatively simply to achieve.
My own idea would be to actually implement Email somehow. So my phone could get an email on my google account (which in turn creates a notification), to which i would send a reply email with my reply. Which in turn will be read out on my server.
The bad part is that i would have to actually open gmail and type out a short message to send back as a reply. So anything easier then that would be a great thing.
I have seen newer android 6 apps use custom buttons in notifications in order for the app to act on, but i have no clue how hard those are to implement and rig to my reply.
Please note that this application is probably nothing that will go public. So i am not going to bother to worry about load or efficiency in the end of it. Since it will be just me and my server.
Any input would be greatly appreciated. The most convenient/easy-to-use method will be marked as the answer.
I think...u can use xml-rpc " http://xmlrpc.scripting.com " for communicating with your server and android app.
I used it in my personal project and found iI to be useful.In my case,I used wordpress as framework so any new updates in my server is notified by this protocol.

How can I get my app to listen for Incoming SMS messages?

I have a windows form App which is written to send and recieve texts, this is implemented by sending a message via .NET Remoting to a Service installed on a server, which has a GSM modem (dongle) connected to it, the service then sends the message through the GSM modem once it has a message from the Client App.
Everything's going well so far with regards to sending a text, However we need functionality to enable the reading of incoming text messages; I'm unsure how to go about writing my code to listen out for incoming texts, and then send them over to my Client App.
Could anyone give me some pointers on where to start please? I've tried MSDN Documentation on the TcpClientChannel Classes, but this doesn't prove useful for listening to the COM port or anything like that.
If you are using the AT command set then I'm afraid your server will have to poll the dongle's SIM for messages at an interval (whatever makes sense).
In terms or notifying the client you can either:
follow the same scheme as the server and poll regularly
-or-
if the remoting connection is open continuously, have the server notify using an event on one of your remoting objects. The event args for this event can contain all of the new messages.

How to implment a GCM Server in C# that supports CCS

I'm trying to write a 3rd party server application for sending and receiving notifications from Android devices using GCM's CCS as outlined here. I'm leveraging PushSharp for handling the sending of notifications from my server app, but I can't seem to find any documentation on how to receive messages at the server level. Is this supported or is there another 3rd party XMPP library for .NET that handles this cleanly?
I dont think you can receive messages at server level, this is not the point in push notifications. if you want to send information to the service from the app, i would suggest writing a webservice. i've implemented this myself, and had to do a little digging to find some code that could communicate with the webservice as it was written in c# and the app was java, but i can paste some code that might help if you think that would help you communicate.
Long story short though, if you want an app to talk to a server, then write a web service. if you want a server to talk to an app, use push notifications.

Android connecting to a .NET application and sending text

I have a C# .NET application listening on a specific port for data (SocketServer).
Using Android, I would like to connect to that SocketServer and send text data to it. I do not know where to get started - sample code would be great.
Take a look at TCP .NET/C# Server with Java client?.
Other than that, you could always recode your server into a REST service, and then anything can communicate with it. But I know this isn't a good answer as I'm sure you don't want to recode the server.

Driving events across custom TCP Long-Polling server

I’m trying to write a custom TCP based long polling server that will serve as a go-between for other TCP connections that require more persistence than a mobile phone can provide.
The way I’m trying to do it is writing an asynchronous TCP server in C# and a matching TCP Client also written in C#.
The way that long polling works (as far as I understand it) is that you open a TCP connection to a server, and the server Halts before sending data back across the socket. You find a Heartbeat interval that works on a mobile phone network (I’ve heard that around 8 minutes works?) and you send an empty packet if there is no updated data.
This is where my trouble comes in. I can’t figure out how to “link” my client’s request for data with an event handler running on the server…
The flow should be something like this (“client” is on a phone):
User starts my application
Client sends a request to be notified if data has changed
Server “links” (registers) client’s socket object into an “Event handler” that is called by the server’s other TCP connections that I talked about!
Event
o If it is triggered (new data has arrived), Send the data to the client
o If it isn’t triggered (no new data), Send an “EmptyChanges” packet to client
Client receives data on the phone and processes it (calls an event handler based on what type of packet it received and passes the “data” it got from the server to it)
Client sends a request to be notified if data has changed
So, my problem is that I can’t think of a design that will accomplish what I want it to do. The problem is that I don’t know HOW to do #3. How do I “Link” one event handler from another? And these are almost guaranteed to be running on different threads!
So, my application would look something like this (all psuedocode):
Class AppClass
{
Main()
List<Client> clients;
List<DataServers> dataServers;
DataReceivedFromServer(Data stuff)
{
}
MessageReceivedFromPhone(PhoneMessage pm, object sender)
{
//Loop here until HeartBeat interval reached
Int totalTime = 0;
While(totalTime < HEARTBEAT_INTERVAL)
{
If( ) // If we have received data from the server, and the client WANTED that data, send it now
{
}
}
}
}
Kind of? I want it to be event driven, but I'm having the damndest time figuring out how to drive the application with a PUSH driven style vs. what I'm "used" to of Polling.
Please, be kind as I might be doing something overly complicated and stupid because this is my first real attempt at using Socket programming (never needed it) and it's especially hard due to the nature of Cell phones being on transient networks and my server needing to maintain the location of these phones with an OPEN TCP connection.
Server platform: Windows
Server language: C#
Test Client platform: Windows
Test Client language: C#
Target Client platform: Windows Mobile 6.5, iPhone, Android (clients will be written separately)
Target client language: C#, Obj-C or MonoTouch, Java
Just anyone wondering this, I trashed the idea of writing a custom TCP server to manage my connections. There was so much overhead in doing that, I'd basically be replicating writing my own HTTP server, so instead of doing that, I went with the Web Tornado framework in Python as my server and am writing the back end services to communicate through HTTP requests in Web Tornado.
Instead of using Long polling at all, I'm going to use SMS for push notifications. I believe all of the major phone platforms implement something similar to an SMS Interceptor that you write... if an SMS of a certain format comes through, it will run your custom code. This allows me to remove the requirements of using consistent open connections (other than for live chat, which will use a comet style Long poll, but the connection can only remain open if active for about 5 minutes.)
Basically, the Web Tornado framework is serving as an Enterprise bus in my architecture.

Categories