HTTP和插座: [英] HTTP and Sockets:

查看:116
本文介绍了HTTP和插座:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I codeD为我的Andr​​oid手机,它使用一个插座引黄联接来发送和接收这工作得很好,它使用的PrintWriter 和<$文本数据在Java中的应用C $ C>的BufferedReader 润通在如何使用HTTP连接的进程说。我希望借此ipportunity建立HTTP哪里将从套接字不同,所以我希望你能帮助我用下面的。

I coded an application in Java for my Android phone that uses a socket connetion to send and recieve text data which works nicely, it uses PrintWriter and BufferedReader Alot was said in the process about using HTTP connection. I am hoping to take this ipportunity to establish where HTTP would differ from Sockets so I hope you can help me with the following.

1)我用创建套接字连接以下

1) I create a socket connection using the following

服务器端:

serverSocket = new ServerSocket(4444);

客户端:

clientSocket = new Socket(address, portNumber);

所以,什么是客户端和服务器端的HTTP相同呢?

So What would be the HTTP equivalent on the client and server sides?

2)从客户端发送数据给我做以下服务器:

2) To send data from the client to the server I do the following:

pw = new PrintWriter(clientSocket.getOutputStream(),true);

    pw.write(AStringVariableInThisCase+"\n"); 
    pw.flush();

什么会一个HTTP连接中是正确的方式?

What would be the correct manner within an HTTP Connection?

3)收到从客户端发送的数据,在服务器端我做以下内容:

3) To recieve the data sent from the client, on the server side I do the following:

   BufferedReader br = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
   String language = br.readLine();

你会使用HTTP连接是等价?

What would be the equivalent using an HTTP Connection?

我已经设计该程序允许数据到利用其自己的一组类中来回传递与服务器和继续这样做使用的PrintWriter和BuferedReader这样做。

The program I have designed allows data to be passed back and forth with the server using its own set of classes and continues to do so using the PrintWriter and BuferedReader to do so.

感谢您的帮助,您可以区分不同贡献。

Thanks for any help you can contribute with distinguishing the differences.

推荐答案

HTTP是一个的协议的。它被用来通过套接字(通常情况下)。

HTTP is a protocol. It's (generally) used over a socket.

Java提供了 HttpURLConnection类类为使用HTTP通过套接字的一个方便的方法。

Java provides the HttpUrlConnection class for a convenient way of using HTTP over a socket.

这篇关于HTTP和插座:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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