> For the complete documentation index, see [llms.txt](https://simian114.gitbook.io/blog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://simian114.gitbook.io/blog/undefined-1/diary/2021/january/20210117.md).

# 20210117(일)

## 2021-01-17

### 1. 학습 날짜

* 2020-01-17

### 2. 학습 시간

* 10:30 \~ 15:00

### 3. 학습 범위 및 주제

* 액션 케이블

### 4. 학습 목표

* 액션 케이블 학습하기

### 5. 학습 정리

* x

### 6. 상세 학습 내용

**액션 케이블**

* 액션케이블은 레일즈에서 웹소켓 프로토콜을 프레임워크 아래에서 사용할 수 있게 해주는 기능이다.

**용어**

* Connections: 커넥션이란 클라이언트와 서버간의 관계의 성립이다.
  * 하나의 액션 케이블 서버는 여러개의 커넥션 객체를 만들 수 있다.&#x20;
    * 즉 여러 명의 클라이언트와 연결될 수 있다는 것이다.&#x20;
  * 그리고 웹소켓 하나당 하나의 연결의 생긴다.
  * 한명의 유저는 브라우저의 탭, 서로 다른 기기등을 이용해서 여러 개의 웹소켓을 만들수있다.
* Consumer
  * 웹소켓과 연결된 클라이언트를 컨슈머라고 부른다.
  * 액션케이블에서 컨슈머는 클라이언트 사이드인 자바스크립트 프레임워크 단에서 생성된다.
* Channel
  * 각각의 컨슈머는 여러 개의 채널을 구독할 수 있다.
* Subscriber
  * 컨슈머가 채널을 구독하면 이를 subscriber이라고 한다.

**사용법**

* `rails g channel room` 명령어로 `room_channel` 을 만든다.
* 이렇게 채널을 만들면 클라이언트 사이드 파일과 서버 사이드 파일이 만들어진다.
  * 클라이언트사이드 파일은 `javascript` 파일로 생성
  * 서버사이드 파일은 `ruby` 파일로 생성
* JS 파일에서 클라이언트가 서버에 연결됨을 명시할 수 있다. 이렇게 클라이언트와 서버가 연결이 되면 이제 웹소켓 프로토콜에 따라 서버거 클라이언트의 요청 없이도 응답을 보낼 수 있게 된다.
  * 여기서 클라이언트가 어떤 채널, 어떤 방에 접속하는지도 명시 할 수 있다.
  * 적절한 제어문을 사용해서 클라이언트가 어떤 채널의 몇번 방의 컨슈머로 만드는게 중요하다
* 클라라이언트가 컨슈머가 되면, 즉 create 동작이 처음 발생하면 `connected()` 함수를 클라이언트 프레임워크에서 발생시킨다. 이 함수는 처음에만 발동함!
* 이렇게 어떤 채널, 어떤 방이 생성되면 해당 방에 ActionCable 클래스를 통해서 브로드캐스팅으로 연락을 줄 수 있다.

### 7. 오늘 학습 내용에 대한 개인적인 총평

* 공부해야하는데 손에 안잡힌다...

### 8. 다음 학습 계획

* 액션 케이블


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://simian114.gitbook.io/blog/undefined-1/diary/2021/january/20210117.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
