웹브라우저가 TCP 커넥션을 통해서 웹 서버에 요청을 보냄.
TCP는 HTTP에게 신뢰할 만한 통신 방식을 제공함. 이때 전송되는 바이트들은 순서에 맞게 반대로 전달됨.
TCP 스트림은 세그먼트로 나뉘어 IP 패킷을 통해 전송됨.
http와 https 네트워크 프로토콜 스택
IP 헤더는 발신지, 목적지 IP 주소, 크기, 기타 플래그를 가짐.
TCP 세그먼트 헤더는 TCP 포트 번호, TCP 제어 플래그, 데이터의 순서와 무결성을 검사하기 위한 숫자 값을 가짐.
IP 패킷은 TCP 데이터 스트림의 덩어리를 운반하는 TCP 세그먼트를 실어 나름.
컴퓨터는 여러 개의 TCP 커넥션을 가짐. TCP는 포트 번호를 통해서 이런 여러 개의 커넥션을 유지함.
TCP 커넥션은 <발신지 IP 주소, 발신지 포트, 수신지 IP 주소, 수신지 포트>
로 식별함.
TCP 커넥션의 생성을 하기 위한 기능으로 소켓 API
를 사용함.
Sockets API call | Description |
---|---|
s = socket(<parameters>) | Creates a new, unnamed, unattached socket. |
bind(s, <local IP:port>) | Assigns a local port number and interface to the socket. |
connect(s, <remote IP:port>) | Establishes a TCP connection to a local socket and a remote host and port. |
listen(s,...) | Marks a local socket as legal to accept connections. |
s2 = accept(s) | Waits for someone to establish a connection to a local port. |
n = read(s,buffer,n) | Tries to read n bytes from the socket into the buffer. |
n = write(s,buffer,n) | Tries to write n bytes from the buffer into the socket. |
close(s) | Completely closes the TCP connection. |
shutdown(s,<side>) | Closes just the input or the output of the TCP connection. |
getsockopt(s, . . . ) | Reads the value of an internal socket configuration option. |
setsockopt(s, . . . ) | Changes the value of an internal socket configuration option. |
클이언트와 서버가 TCP 소켓 인터페이스를 사용하여 상호작용하는 방법
<aside> 👀 고성능의 HTTP 소프트웨어를 개발하고 있는 게 아니라면 완벽히 이해할 필요는 없음.
</aside>
TCP_NODELAY
파라미터 값을 설정하여 네이글 알고리즘을 비활성화할 수 있지만, 작은 크기의 패킷이 너무 많이 생기지 않도록 큰 크기의 데이터 덩어리를 만들어야 함.TIME_WAIT
이란 TCP 상태의 가장 마지막 단계에서 발생함.