1 / 10

Socket Programming

[OOP study]. Socket Programming. Jungsik Yoon NML. GIST 2009. 11. 25. What is socket?. 응용 프로그램이 데이터를 보내고 받을 수 있는 OS 가 제공하는 추상적인 통로 응용 프로그램이 저장 장소에 데이터를 읽고 쓰는 과정을 open 된 파일을 통해서 처리하는 것과 유사

auryon
Télécharger la présentation

Socket Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. [OOP study] Socket Programming Jungsik Yoon NML. GIST 2009. 11. 25

  2. What is socket? • 응용 프로그램이 데이터를 보내고 받을 수 있는 OS가 제공하는 추상적인 통로 • 응용 프로그램이 저장 장소에 데이터를 읽고 쓰는 과정을 open된 파일을 통해서 처리하는 것과 유사 • 구조적으로는 OS(Windows/Linux)가 제공하는 네트워크 (Local Computer 외부로 보내는 데이터가 존재)를 필요로 하는 응용 프로그램을 위해 제공하는 API

  3. Socket in structure APP Port # Socket(TCP/UDP) NetworkSystem(in LINUX) TCP UDP IP Network Device Driver Network Device

  4. 리눅스 디바이스 드라이버 구성 응용프로그램 User Space 시스템 호출 인터페이스 Kernel Space 가상 파일 시스템 (VFS) 버퍼 캐시 네트워크 시스템 문자 디바이스 드라이버 블록 디바이스 드라이버 네트워크 디바이스 드라이버 Hardware 하드웨어

  5. Example APP APP Socket(TCP/UDP) NetworkSystem(in LINUX) TCP TCP UDP UDP Network Device Driver Network Device Driver IP IP Network Device Network Device

  6. 기본 함수 • 소켓의 생성 • protocolFamily: 소켓 API는 다수의 프로토콜 패밀리에 대해 하나의 총괄적인 인터페이스를 제공하는 것임. 이들 중 한가지인 PF_INET은 인터넷 프로토콜 패밀리의 프로토콜들을 사용하는 소켓 이름. • type: 소켓의 형태로, PF_INET을 이용하는 경우TCP 또는 UDP 타입을 선택 하는 부분임.(TCP: SOCK_STREAM, UDP: SOCK_DGRAM) • protocol: 사용할 특정 E2E 프로토콜. type과 같은 프로토콜을 사용함.(TCP: IPPROTO_TCP, UDP: IPPROTO_UDP) intsocket (intprotocolFamily, inttype, intprotocol)

  7. 소켓의 해지 • 하부 프로토콜에 통신을 종료하기 위해 필요한 조치를 취하고 소켓과 관련한 할당된 자원을 최수하라는 지시를 내림. 성공시0, 실패시-1을 반환함. close( )가 호출된 이후에는 해당 소켓을 이용하여 더 이상 통신이 불가능 함. int close (intsocket)

  8. 주소 지정 • 소켓을 사용하는 응용 프로그램은 커널에 인터넷 주소와 포트를 지정할 수 있는 방법이 필요함. structsockaddr{ unsigned short sa_family; /* Address family (e.g. AF_INET) */ char sa_data[14]; /* Family-sepcific address information*/ } sa_family sa_data (14bytes) sockaddr 2 bytes 2 bytes 4 bytes 8 bytes sockaddr_in Family Port IP addr Unused sin_family sin_port sin_addr sin_zero

  9. TCP/IP 소켓주소 structin_addr{ unsigned long s_addr; /* Internet address (32bits) */ }; structsockaddr_in { unsigned short sin_family; /* Internet protocol (AF_INET) */ unsigned short sin_port; /* Port Addr (16bits) */ structin_addrsin_addr; /* IP Addr (32bits) */ char sin_zero[8]; /* Not used */ }

  10. Example (Server-Client 구조) • TBD..

More Related