Connect to server with sub-directory in java

天大地大妈咪最大 提交于 2019-12-11 17:26:22

问题


Is it possible to connect to a server with sub-directory?

for example: www.example.com:80/server.

I want to receive the data from the server with a Socket.

Something like this:

String url = "example.com:80/server";
Socket client = new Socket(url);

回答1:


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.

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.



来源:https://stackoverflow.com/questions/29429745/connect-to-server-with-sub-directory-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!