平板电脑(iPad版/ Android的) - 服务器通信协议 [英] Tablet(iPad/Android)-Server Communication Protocol

查看:333
本文介绍了平板电脑(iPad版/ Android的) - 服务器通信协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建立一个客户端 - 服务器应用程序。这里的客户端是一台iPad(或基于Android的)平板电脑。服务器是一个正常的PC。两个客户端和服务器(使用WiFi)连接到相同的网络。

I am going to build a client-server application. The client here is an iPad (or an android-based) tablet. The server is a normal pc. Both the clients and the server are connected to the same network (using WiFi).

有没有一种标准方式(协议)的客户端和服务器之间的通信?是否有可用于减轻这种通信的任何框架?

Is there a standard way (protocol) for communication between the clients and the server? Are there any framework that can be used to ease this communication?

感谢您

推荐答案

答案取决于由你所说的服务器,客户和协议中定义。

The answer depends by what you define by "server", "client", and "protocol".

技术上,答案是是;从实际情况来看,你正在寻找的被称为插座,但对于协议的事情的框架可能会变得复杂。

Technically, the answer is "yes"; from a practical standpoint the framework you are looking for is called "socket", but regarding the protocol things may get complicated.

一个协议是管理数据交换,也就是说,你用它来要求一组规则语法结构/提供服务(见的在IETF网站为标准的人的列表)。 插座,在另一方面,提供你只是一个通信信道,以从一侧到另一带上的字节和在其上的顶部,以实现协议你是必需的。 好消息是,插座是独立的语言,你可以将异构设备(新iPad /安卓/ Linux / Windows的)。

A protocol is a syntax structure governing data exchange, i.e., a set of rules you use to request/provide a service (see the IETF website for a list of standard ones). Sockets, on the other hand, provide you merely a communication channel to bring bytes from one side to another and, on top of which, you are required to implement the protocol. The good news is that socket are language independent and you can send messages between heterogeneous devices (ipad/android/linux/windows).

在Java中使用的插座很容易(我拍得很短这里)

Using sockets in java is easy (I am making it very short here)

服务器端

ServerSocket ss = new ServerSocket(port);
Socket s = ss.accept();
InputStream is = s.getInputStream();

客户端

Socket s = new Socket("server.address", port); // same port as above
OutputStream os = s.getOutputStream();

当你使用写东西的 os.write()的相同的字节将被读出的 is.read()的。 什么您写的操作系统的是你的协议的执行情况。

When you write something using os.write() the same bytes will be read by is.read(). What you write on os is the implementation of your protocol.

本主题涵盖(对于Java语言)很好由布鲁斯·埃克尔,你可以的访问数字版是免费的。 在C / C ++ / Objective C的事情比较复杂,但你可以很容易谷歌的教程。

This topic is covered (for java language) quite well by "Thinking in Enterprise java" by Bruce Eckel, you can access the digital edition for free. In C/C++/Objective C things are more complicated but you can easily google for tutorials.

每个服务定义了自己的协议,你应该决定是否对现有的人会做,或者你必须定义自己的,取决于你想要在两个设备之间实现哪些服务。

Each service defines its own protocol and you should decide if one of the existing will do or you have to define your own, depending on which service you want to implement between the two devices.

如果,在标准方法中,PC扮演着服务器的角色,客户想要从它的信息,你可能要考虑使用安装一个(非常)轻量级的Web服务器和访问数据的的HttpURLConnection 。这是一个包装与HTTP协议的管理接口已经实现。 当心,这是Java;没有标准框架等C / C ++,老实说,我还真不知道目标C.

If, as in the standard approach, the PC plays the role of server and clients want to retrieve information from it, you might want to consider installing a (very) lightweight web server and access data using HTTPUrlConnection. This is a wrapper for a socket with HTTP protocol management already implemented. Beware, this is for Java; there is no "standard framework equivalent" for C/C++, I honestly have no idea about objective C.

请,也可以注意以下问题:

Please, be also aware of the following:

  • 如果客户端和服务器具有不同的体系结构的二进制数据交换可能会痛苦,更好地定义你的协议作为字符串(如SMTP)的序列和连接code /德code使用Base64二进制文件或其他一些方法,你可能需要实施
  • 在为了连接两个插槽客户端必须知道服务器的IP地址;如果你正在运行DHCP WiFi网络,那么你还需要实现一个发现阶段为您服务

作为最后一个侧面说明:客户端和服务器只是标签,你把通信实体取决于谁在请求服务/信息(客户端),谁提供它(服务器)。通信是在现实对称的,你可以用相同的结构/功能/ code的两个端点。

As a last side note: "client" and "server" are just labels you put on communicating entities depending on who is requesting a service/information (client) and who is providing it (server). Communication is in reality symmetrical and you can use the same structures/functions/code on both endpoints.

这篇关于平板电脑(iPad版/ Android的) - 服务器通信协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆