简体   繁体   English

如何使用Java建立与服务器的连接?

[英]How do you establish a connection to a server in Java?

I want to create an application which will connect to a file server and download a few video files. 我想创建一个将连接到文件服务器并下载一些视频文件的应用程序。 The server is a shared hosting Linux server. 该服务器是共享的托管Linux服务器。

I don't want code or anything like that, I just want to know whether this is possible and if so, what should I be researching. 我不想要代码或类似的东西,我只想知道这是否可能,如果可能,我应该研究什么。 Should I be using java sockets? 我应该使用Java套接字吗? Or can Java sockets only connect to java based servers? 还是Java套接字只能连接到基于Java的服务器?

Should I be using java sockets? 我应该使用Java套接字吗?

Depends on the type of server you connect to. 取决于您连接到的服务器的类型。 You can use an existing library which will abstract the interaction with the server for you (recommended) or implement the required protocol yourself (not recommended). 您可以使用现有的库来为您抽象与服务器的交互(推荐),也可以自己实现所需的协议(不推荐)。

Can Java sockets only connect to java based servers? Java套接字只能连接到基于Java的服务器吗?

Sockets in Java are just an interface to the native socket API of the OS you are on. Java中的套接字只是您所使用的操作系统的本机套接字API的接口。 Every program that connects to a server over the network has to use them, regardless of whether it is a C/C++/Python/Java/... application. 通过网络连接到服务器的每个程序都必须使用它们,而不管它是否是C / C ++ / Python / Java / ...应用程序。 So, to answer your question; 因此,回答您的问题; no, "Java sockets" can connect to any server. 不,“ Java套接字”可以连接到任何服务器。

Read more about sockets in this Wikipedia article about sockets in general or this one about Berkeley sockets (the socket API implemented by most operating systems). 此Wikipedia文章中了解有关套接字的更多信息,或阅读有关Berkeley套接字 (大多数操作系统实现的套接字API)的文章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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