为什么tomcat的收到请求时

为什么tomcat的收到请求时

本文介绍了为什么tomcat的收到请求时,多个进程监听的端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现了 SO_REUSEADDR 的窗口;并通过tomcat的使用这个。

I recently found out about SO_REUSEADDR on windows; and that tomcat uses this by default.

我做了一个小测试,以找出当另一个进程也听相同的端口会发生什么。在我的情况的另一个过程是的netcat 。结果令人惊讶:

I did a small test to find out what happens when another process is also listening to the same port. The other process in my case was netcat. The results were surprising:


  • 不管我是否启动 NC 的netcat )第一或的tomcat ,如果从Tomcat的响应

  • 如果我停止与它的斌/ tomcat的tomcat.bat 也杀死了 NC 过程

  • 如果我通过中止进程,然后NC能够到下一个连接回应停止Tomcat

  • Irrespective of whether I start nc (netcat) first or tomcat, the response if from tomcat
  • If I stop tomcat with its bin/tomcat.bat it also kills the nc process
  • If I stop tomcat by killing the process then nc is able to respond to the next connection

什么神奇的东西?如何为tomcat的总是能抢到传入的请求?这是(tomcat会为所有的连接,即使其他进程听力)担保的行为吗?我无法想象它如何能够保证,但想到要问。

What magic is this? How is tomcat always able to grab incoming request? Is this (tomcat will serve all connections even if other processes are listening) guaranteed behavior? I cannot imagine how it can be guaranteed but thought to ask.

推荐答案

我能够从问题的回答这个问那个响应用户号我的<一个href=\"http://stackoverflow.com/questions/21031229/how-to-disable-so-reuseaddr-in-tomcat?noredirect=1#comment31617225_21031229\">other问题。

I was able to answer this from the question that user nos asked in response to my other question.

我意识到,因为我是用的wget的http://本地主机:8080 在我的测试中,它使用的IPv6 只tomcat的在听上。

I realized that since I was using wget http://localhost:8080 in my test, it was using IPv6 which only tomcat was listening on.

当我改成了 http://127.0.0.1:8080 我看到了完全不同的行为。

When I changed it to http://127.0.0.1:8080 I saw completely different behavior.

这篇关于为什么tomcat的收到请求时,多个进程监听的端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 08:33