- 연결지향 프로토콜이다.
- 전송 전에 TCP 연결을하고 소켓을 이 연결을 통해 보내 통신한다.
- 당연히 three-way handshaking도 포함된다.→ 연결 포트가 아닌 환영(welcom) 포트로 시도
연결 포트는 이 때 생성된다.
- TCP 연결을 통해 클라이언트 서버 모두 전송과 수신이 가능하다.


TCPClient.py
from socket import *
serverName = 'ip주소'
serverPort = 12000
clientSocket = socket(AF_INET, SOCK_STREAM) -> IPv4 , UDP 를 의미
clientSocket.connect((serverName, serverPort)) -> TCP 연결부터 진행
sentence = input('input lower sentence:')
clientSocket.send(sentence.encode) -> 전송
modifiedSentence = clientSocket.recvform(2048) -> 2048 버퍼의 크기로 받는다
print(modifiedMessage.decode())
clientSocket.close()
UDPServer.py
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_STREAM) -> handshaking을 위한 환영포트
serverSocket.bind(('',serverPort)). -> 포트번호 12000을 서버의 소켓에 할당한다(bind)
serverSocket.listen(1) -> 최대 한개의 TCP 연결 요청을 듣는 중을 의미
print("The server is ready to recieve")
while True: -> 요청을 무한으로 대기하는 모습
connectionSocket, addr = serverSocket.accept()
-> 환영포트에서 두들기면 connectionSocket생성
sentence = serverSocket.recvfrom(2048).decode()
capitalizedSentence = sentence.upper()
connectionSocket.sendto(capitalizedSentence.encode())
connectionSocket.close()
-> connectionSocket은 닫혀 있지만 serverSocket은 열려있기에 요청을 받을 수 있다.