简体   繁体   中英

Communications between a C# PC program and an android tablet app

So the goal is that the tablet can read and write a value of the PC program.

So far I have managed to solve this.

I have :

an android app which uses ksoap2.

a web server, ASP.NET in C#

and the main program in C#

Example :

tablet calls a web method of the web server -> setA(42)

web server change its static value of a to 42

main program calls a web method of the web server -> getA() and so it can save the 42 in his own a attribute.

So it does the job but it s quiet heavy. I am just exchanging integers or strings. I've heard of socket programming but it appears to be less easy to use especially with firewalls, corporate networks... any ideas :) ?

Obviously you get a lot of overhead with a web service but much less coding.. Setting up you own socket connection is not really a big deal as both Java(android) and .Net have nice simple support for this.

http://developer.android.com/reference/java/net/Socket.html

http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx

I would not go for sockets. As you say, firewalls and routes can be a problem. HTTP is usually open. It's also easier to scale services that use HTTP since everything needed already exists (such as load balancers). You could even direct different versions of your protocol to different servers by using a HTTP proxy.

For that simple requests, simply put everything in the URI:

http://yourservice.com/v1/productname/seta/?value=42

Use JSON for a bit more complex requests:

http://yourservice.com/v1/seta

{
   "a": 42,
   "b": "Something"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM