开发者

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"
}
  • JSON in android: http://developer.android.com/reference/org/json/JSONObject.html
  • JSON in C#: asp.net mvc has built in support.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜