是否为每个请求创建了新套接字? [英] Is new socket created for every request?

查看:74
本文介绍了是否为每个请求创建了新套接字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图把头放在网络套接字上.到目前为止,我的理解是服务器创建了一个绑定到特定端口的新套接字.然后它监听这个套接字来处理客户端请求.

我已阅读本教程 http://docs.oracle.com/javase/tutorial/networking/sockets/definition.html 它说

<块引用>

如果一切顺利,服务器接受连接.验收后,服务器获取绑定到同一本地端口的新套接字,并且还具有它的远程端点设置为客户端的地址和端口.它需要一个新的套接字,以便它可以继续侦听原始套接字连接请求,同时满足连接客户端的需求.

这里有一些我不太明白的地方

<块引用>

如果一切顺利,服务器接受连接.

  1. 这是否意味着客户端请求成功到达侦听套接字?

<块引用>

接受后,服务器获得一个绑定到同一本地端口的新套接字,并且还将其远程端点设置为客户端的地址和端口

  1. 新的套接字被创建.它也被绑定到同一个端口,但它不侦听传入的请求.服务器处理完客户端请求后,将请求响应写入此套接字,然后将其关闭.这是正确的吗?

  2. 这是否意味着请求以某种方式从第一个套接字传递到第二个套接字?

<块引用>

它需要一个新的socket才能继续听原来的用于连接请求的套接字,同时满足连接客户端的需求.

  1. 因此,创建了新的套接字,然后侦听传入的请求.有不同类型的插座吗?某种监听"套接字和其他?

  2. 为什么服务器要创建一个新的监听套接字?为什么不能重用以前的?

解决方案

  1. 没有.这意味着传入连接到达服务器.
  2. 没有.如果服务器关闭它,它就会关闭.否则.
  3. 没有.这意味着传入连接会导致完全形成连接并在服务器上创建一个套接字来表示它的服务器端端点.
  4. (a) 否.创建一个新的套接字来接收请求并发送响应.(b) 是的.有被动和主动插座.被动套接字侦听连接.活动套接字发送和接收数据.
  5. 它不必创建新的侦听(被动)套接字.它必须创建一个新的活动套接字作为新连接的端点.

<块引用>

是否为每个请求创建新的套接字?

大多数协议,例如带有 keep-alive 的 HTTP,允许每个连接有多个请求.

I am trying to wrap my head around network sockets. So far my understanding is that a server creates a new socket that is bound to the specific port. Then it listens to this socket to deal with client requests.

I've read this tutorial http://docs.oracle.com/javase/tutorial/networking/sockets/definition.html and it says

If everything goes well, the server accepts the connection. Upon acceptance, the server gets a new socket bound to the same local port and also has its remote endpoint set to the address and port of the client. It needs a new socket so that it can continue to listen to the original socket for connection requests while tending to the needs of the connected client.

Here are a few things that I don't quite understand

If everything goes well, the server accepts the connection.

  1. Does it mean that a client request successfully arrived at the listening socket?

Upon acceptance, the server gets a new socket bound to the same local port and also has its remote endpoint set to the address and port of the client

  1. The new socket is created. It also gets bound to the same port but it doesn't listen for incoming requests. After server processed client request resonse is written to this socket and then it gets closed. Is it correct?

  2. Does it mean that request is somehow passed from the first socket to the second socket?

It needs a new socket so that it can continue to listen to the original socket for connection requests while tending to the needs of the connected client.

  1. So, the new socket is created then that listens for incoming request. Are there different type of sockets? Some kind of "listening" sockets and other?

  2. Why does the server have to create a new listening socket? Why can't it reuse the previous one?

解决方案

  1. No. It means that an incoming connection arrived at the server.
  2. No. It gets closed if the server closes it. Not otherwise.
  3. No. It means that the incoming connection causes a connection to be fully formed and a socket created at the server to represent the server-end endpoint of it.
  4. (a) No. A new socket is created to receive requests and send responses. (b) Yes. There are passive and active sockets. A passive socket listens for connections. An active socket sends and receives data.
  5. It doesn't have to create a new listening (passive) socket. It has to create a new active socket to be the endpoint of the new connection.

Is new socket created for every request?

Most protocols, for example HTTP with keep-alive, allow multiple requests per connection.

这篇关于是否为每个请求创建了新套接字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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