How Tomcat work Porter Charpter 3:connector

Source: Internet
Author: User

This chapter mainly introduces an important module of Tomcat connector, but only a reduced version

The role of connector is to create an instance of ServerSocket ServerSocket, a bound port, a listening port, and when accepted to a client request, creates a Httpprocessor instance processor, Use ServerSocket as a parameter to Httpprocessor instance processor.process (ServerSocket) to process the request

import java.io.ioexception;import java.net.inetaddress;import java.net.serversocket;import java.net.Socket; Public classHttpConnector implements Runnable {Boolean stopped; PrivateString scheme ="http";  PublicString Getscheme () {returnscheme; }   Public voidrun () {ServerSocket ServerSocket=NULL; intPort =8080; Try{ServerSocket=NewServerSocket (Port,1, Inetaddress.getbyname ("127.0.0.1")); }    Catch(IOException e) {e.printstacktrace (); System.exit (1); }     while(!stopped) {      //Accept the next incoming connection from the server socketSocket socket =NULL; Try{Socket=serversocket.accept (); }      Catch(Exception e) {Continue; }      //Hand This socket off to an httpprocessorHttpprocessor processor =NewHttpprocessor ( This);    Processor.process (socket); }  }   Public voidstart () {Thread thread=NewThread ( This);  Thread.Start (); }}

How Tomcat work Porter Charpter 3:connector

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.