Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

ftp

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)?

like image 498
Katy Strahan Avatar asked Oct 14 '25 09:10

Katy Strahan


1 Answers

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#?

like image 156
Rocket Avatar answered Oct 17 '25 01:10

Rocket



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!