Katy Strahan
Katy Strahan

Reputation: 51

How to establish simple communication between android app and C# desktop app

I've created C# application which is running (almost non-stop) on my windows 7 desktop computer. Now I'm looking for a simple way to tell my desktop application to stop running from my android phone. My initial plan was to have .txt file on my ftp server, so desktop app would check i.e. every hour if .txt file contains command to shut down (pressing a button on android app would change .txt file on ftp server). However even after few hours of tutorials on java I was still unable to figure out working with ftp connection.

What would be easiest way given my lack of java knowledge (I understand I'll have to learn a bit more, but I really don't want to get too deep into java for now)?

Upvotes: 4

Views: 1995

Answers (1)

Michael Möbius
Michael Möbius

Reputation: 1050

The simplest way would be to send a simple udp or tcp message to your windows application. http://developer.android.com/reference/java/net/DatagramSocket.html

String messageStr="Shutdown!";
int server_port = 8855;
DatagramSocket s = new DatagramSocket();
InetAddress local = InetAddress.getByName("192.168.1.55");
int msg_length=messageStr.length();
byte[] message = messageStr.getBytes();
DatagramPacket p = new DatagramPacket(message, msg_length,local,server_port);
s.send(p);

In your C# Application you simply open a Socket and wait for your packet. How do I make a UDP Server in C#?

Upvotes: 6

Related Questions