Skip to content

Commit

Permalink
chore: Fix numbering
Browse files Browse the repository at this point in the history
  • Loading branch information
1ilsang committed Apr 5, 2021
1 parent a7ab132 commit 2d34b1f
Show file tree
Hide file tree
Showing 54 changed files with 14 additions and 46 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 6 additions & 29 deletions part1/chapter3.md → part1/chapter03.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
## Chapter 3: 주소체계와 데이터 정렬



### Internet Address

- IPv4: 4바이트 주소체계

- 네트워크 주소 + 호스트 주소
- 클래스
- 클래스
- 첫 바이트 범위 A: 0-127, B:128-191, C: 192-223

- IPv6: 16바이트 주소체계



### PORT 번호

- 최종 목적지(응용 프로그램)
- NIC(네트워크 인터페이스 카드) 수신 -> 운영체제 PORT 분배



### IPv4 기반의 주소표현을 위한 구조체

```c
Expand All @@ -33,19 +27,17 @@ struct sockaddr_in
}
```



### 네트워크 바이트 순서

- Big Endian
- Big Endian

- 0x12345678 -> 0x12, 0x34, 0x56, 0x78

- Little Endian
- Little Endian

- 0x12345678 -> 0x78, 0x56, 0x34, 0x12

- 네트워크 바이트 순서는 **Big Endian** 으로!
- 네트워크 바이트 순서는 **Big Endian** 으로!

- 바이트 변환

Expand All @@ -56,8 +48,6 @@ struct sockaddr_in
unsigned long ntohl(unsigned long);
```
### 문자열을 네트워크 바이트 순서 정수로 변환
```c
Expand All @@ -66,21 +56,19 @@ in_addr_t inet_addr(const char * string); // Big Endian 32비트 정수 변환
int inet_aton(const char * string, struct in_addr * addr); // in_addr 구조체 사용
```



### 인터넷 주소의 초기화

```c
struct sockaddr_in addr;
char *serv_ip="211.217.168.13"; // IP 주소
char *serv_ip="211.217.168.13"; // IP 주소
char *serv_port="9190"; // PORT 번호
memset(&addr, 0, sizeof(addr)); // 초기화
addr.sin_family=AF_INET; // 주소체계
addr.sin_addr.s_addr=inet_addr(serv_ip); // 문자열 IP주소 초기화: serv_ip -> INADDR_ANY
addr.sin_port=htons(atoi(serv_port)); // 문자열 PORT 번호 초기화
```
- 클라이언트 주소의 초기화
- 클라이언트 주소의 초기화
bind 대신 connect 함수 사용
Expand All @@ -92,8 +80,6 @@ addr.sin_port=htons(atoi(serv_port)); // 문자열 PORT 번호 초기화
int bind(int sockfd, struct sockaddr *myaddr, socklen_t addrlen);
```



### 윈도우 소켓 인터넷 주소 할당

```c
Expand All @@ -110,12 +96,3 @@ INT WSAAddressToString( // 주소정보 구조체 변수 -> 주소정보 문자
LPDWORD lpdwAddressStringLength
);
```









25 changes: 8 additions & 17 deletions part1/chapter4.md → part1/chapter04.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Chapter 4 : TCP 기반 서버/클라이언트 1


## TCP/IP 프로토콜 스택

```
Expand Down Expand Up @@ -50,16 +49,12 @@ TCP의 경우에는 신뢰성 있는 데이터 전송을 담당한다. 즉, IP

위 3개의 계층은 `socket` 을 생성하면 데이터 송수신과정에서 자동으로 처리된다.

즉, 네트워크 프로그래밍에서는 이러한 과정을 신경쓰지 않아도 된다. socket을 이용해서 프로그램을 만들게 되면 클라이언트와 서버간의 데이터 송수신에 대한 규칙들이 생기는 데 이를 **APPLICATION 프로토콜**이라 부른다.


즉, 네트워크 프로그래밍에서는 이러한 과정을 신경쓰지 않아도 된다. socket을 이용해서 프로그램을 만들게 되면 클라이언트와 서버간의 데이터 송수신에 대한 규칙들이 생기는 데 이를 **APPLICATION 프로토콜**이라 부른다.

## TCP 기반 서버, 클라이언트 구현

### 서버



```
// TCP 서버의 함수 호출순서
socket() : 소켓 생성
Expand All @@ -86,9 +81,7 @@ int listen(int sock, int backlog); // 성공시 0, 실패시 -1
> sock - 연결 요청 대기 상태로 두고자 하는 소켓의 파일 스크립터
> backlog - 연결 요청 대기 큐의 크기
bind 함수를 통해 소켓에 주소할당한 후에 listen을 통해 서버는 클라이언트의 *연결 요청 대기 상태* 로 들어가게 된다. 즉, listen 함수가 호출되어야 클라이언트는 connect 함수를 통해 서버에 연결 요청을 할 수 있다.
bind 함수를 통해 소켓에 주소할당한 후에 listen을 통해 서버는 클라이언트의 _연결 요청 대기 상태_ 로 들어가게 된다. 즉, listen 함수가 호출되어야 클라이언트는 connect 함수를 통해 서버에 연결 요청을 할 수 있다.
#### accept()
Expand All @@ -108,9 +101,7 @@ int accept(int sock, struct sockaddr * addr, socklen_t * addrlen);
- 데이터 입출력에 사용할 소켓 생성
- 연결요청한 클라이언트 소켓과의 연결

[hello_server.c 소스코드](https://github.com/Road-of-CODEr/tcp-ip-hot-blood/blob/master/codes/Chapter1%20%EC%86%8C%EC%8A%A4%EC%BD%94%EB%93%9C/hello_server.c)


[hello_server.c 소스코드](https://github.com/Road-of-CODEr/tcp-ip-hot-blood/blob/master/codes/Chapter01%20%EC%86%8C%EC%8A%A4%EC%BD%94%EB%93%9C/hello_server.c)

### 클라이언트

Expand Down Expand Up @@ -138,19 +129,19 @@ int connect(int sock, struct sockaddr * servaddr, socklen_t addrlen); // 성공
> addrlen - 서버 주소정보 변수의 크기를 바이트 단위로 전달
- 서버에 연결요청을 보낸다.
- 서버에 의해 연결 요청 접수
- 서버의 연결요청 대기 큐에 등록된 상황 (`accept()` 함수호출을 의미하는 것이 아니다)
- 즉, connect 함수가 반환되더라도 당장에 서비스가 이뤄지지 않을 수 있다
- 클라이언트 소켓에 IP와 PORT 할당
[hello_client.c](https://github.com/Road-of-CODEr/tcp-ip-hot-blood/blob/master/codes/Chapter1%20%EC%86%8C%EC%8A%A4%EC%BD%94%EB%93%9C/hello_client.c)
[hello_client.c](https://github.com/Road-of-CODEr/tcp-ip-hot-blood/blob/master/codes/Chapter01%20%EC%86%8C%EC%8A%A4%EC%BD%94%EB%93%9C/hello_client.c)
### 에코 서버/클라
기본 동작방식
- 서버는 한번에 하나의 클라이언트와 연결되어 에코 서비스 제공
- 서버는 총 다섯개의 클라이언트에 순차적으로 서비스 제공
- 클라이언트는 문자열을 입력받아 서버에 전송
Expand All @@ -167,12 +158,12 @@ bind()
listen()
⬇️
accept()
⬇️
⬇️
read()/write()
⬇️
close(client)
⬇️
close(server)
```
[소스코드](https://github.com/Road-of-CODEr/tcp-ip-hot-blood/tree/master/codes/Chapter4%20%EC%86%8C%EC%8A%A4%EC%BD%94%EB%93%9C)
[소스코드](https://github.com/Road-of-CODEr/tcp-ip-hot-blood/tree/master/codes/Chapter04%20%EC%86%8C%EC%8A%A4%EC%BD%94%EB%93%9C)

0 comments on commit 2d34b1f

Please sign in to comment.