问题描述
是否可以通过子目录连接到服务器?
Is it possible to connect to a server with sub-directory?
,例如:www.example.com:80/server
.
我想使用Socket从服务器接收数据.
I want to receive the data from the server with a Socket.
类似这样的东西:
String url = "example.com:80/server";
Socket client = new Socket(url);
推荐答案
子目录是HTTP和FTP等协议中的高级概念.根据您的示例,您似乎正在尝试连接到HTTP端口.这对您不起作用,因为您必须编写所有代码以实现HTTP协议,以便可以发送有效请求并处理响应.如果那是您想要做的,那么您应该只是那里的许多高级HTTP库之一.
Subdirectories are a high level concept in protocols like HTTP and FTP. Based on your example, you look like you're trying to connect to a HTTP port. This won't work for you because you'd have to write all of the code to implement the HTTP protocol to the point where you could send valid requests and handle the responses. If that's what you want to do, you should just one of the many high level HTTP libraries out there.
如果只想创建一个简单的服务器应用程序,只需在端口example.com
的端口80上打开一个套接字,并编写自己的消息/响应以表示您想要文件夹server
.自定义服务器将必须知道如何处理自己的消息,读取文件夹等.
If you just want to create a simple server app, just open a socket on example.com
, port 80 and write your own messages/responses for saying you want folder server
. The custom server will have to know how to handle your own messages, read folders, etc.
这篇关于使用Java中的子目录连接到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!