[英]Android networking
I'm new to android development I'm writing an application that will talk to a server over TCP/IP I was planning to use the java.net.Socket package but then I've found that there is a android.net.LocalSocket also. 我是Android开发的新手我正在编写一个应用程序,它将通过TCP / IP与服务器通信我计划使用java.net.Socket包,但后来我发现有一个android.net.LocalSocket也。 Does anyone know the difference between these or have a suggestion when to use which one of these. 有没有人知道这些之间的区别或有什么建议何时使用这些中的哪一个。
Thanks 谢谢
java.net.Socket is for creating TCP/IP sockets. java.net.Socket用于创建TCP / IP套接字。
android.net.LocalSocket is for creating unix domain sockets in the abstract namespace or on the filesystem. android.net.LocalSocket用于在抽象命名空间或文件系统中创建unix域套接字 。 These are used for inter process communication. 这些用于进程间通信。
You need to use java.net.Socket as you say you need TCP/IP sockets. 您需要使用java.net.Socket,因为您说需要TCP / IP套接字。
Did you consider checking the API references first? 您是否考虑过首先检查API引用? Here's the definition for java.net.Socket and android.net.LocalSocket . 这是java.net.Socket和android.net.LocalSocket的定义。 The latter is described as, " Creates a (non-server) socket in the UNIX-domain namespace. The interface here is not entirely unlike that of java.net.Socket "; 后者被描述为“ 在UNIX域名称空间中创建一个(非服务器)套接字。这里的接口与java.net.Socket的接口不完全相同 ”; the obvious difference is it has a single public constructor LocalSocket()
. 明显的区别是它有一个公共构造函数LocalSocket()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.