관리 메뉴

HAMA 블로그

Half close socket 이란 본문

Network

Half close socket 이란

[하마] 이승현 (wowlsh93@gmail.com) 2015. 9. 7. 10:38


Half Close 란?

 half-closed connection 을 말하는데  TCP 특성상 양쪽에서 받고 보내는 연결이 2중이 되는데 , 한 쪽만 

닫는것을 말합니다. 종료시에 보통 입력 스트림을 살리고 전송 스트림은 닫습니다. 

When shutting down a TCP connection, something curious occurs. The TCP connection is duplex: data flows in both directions. And it's created in this manner -- it is impossible to create "half" a TCP connection, that would let data flow only from one end to the other. The SYN/ACK handshaking creates both directions at once or fails. Of course, your program might use the TCP connection to stream data in only one direction. But both directions are there...

When closing the connection, something else occurs. A party wishing to close its side of the TCP connection sends a FIN (i.e. a header with this bit set, along with any of the usual ACKs etc.). Like a SYN at the beginning of the connection, the FIN consumes a TCP sequence number, so it can be ACKed. And after the other party ACKs, the connection is half-closed! The party which sent the FIN can no longer send data -- but the other party may continue to send data.To close the TCP stream fully, both sides must send a FIN for "their" half of the connection. What possible use is a half-open connection?

In fact, a great deal of use. TCP streams share a great deal of intended functionality with UN*X pipes. In particular, it is often useful to think of sending a FIN in the same way as sending an EOF to the other side. Many processes can only compute their output after they finish reading their input. If you wish to connect such a program to a TCP stream, you'll need to denote the end of input in some manner -- and that manner is TCP's FIN.

For instance, suppose we have a program md5sum which computes the MD5 checksum of its input. md5sum reads its entire input, and only then generates output. Suppose further I have a file xyzzy on machinealice, and the program md5sum on machine bob. How can I compute the checksum?

alice% rsh bob md5sum < xyzzy

does the trick.

md5sum cannot produce any output until it knows its read all its input. Thus, no application data will flow from bob to alice until alice sends FIN. As soon as alice sends FIN, rsh on bob knows that its standard input has ended, and closes md5sum's input. Now md5sum can output its application data, which is transmitted on the half-open side of the TCP stream. Immediately following this data comes bob's FIN, closing the other half of the connection.

Without the TCP's half-close, some out of band data would have had to be used, significantly complicating TCP. A half-closed pipe is useful.

http://everything2.com/title/TCP+half-close


'Network' 카테고리의 다른 글

keepalive 란?  (0) 2015.07.22
SSH 터널링 상세이론  (0) 2015.07.14
홀펀칭 기초  (0) 2015.07.14
와이파이로 기기간 연결 강화한다  (0) 2015.06.11
모바일기기 wifi의 ip주소를 수동으로 설정하기  (0) 2015.06.11
Comments