일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- isolate
- URLSession
- network
- chartsorg
- swift
- iot
- designpattern
- raspberrypi5
- dart
- philipshue
- Xcode
- dartz
- WWDC24
- SampleApp
- embedded-swift
- OpenAI
- uikit
- weatherkit
- tuist
- GIT
- 문법
- LifeCycle
- flutter
- EventLoop
- dgcharts
- Architecture
- WebSocket
- builder
- SwiftUI
- AppleDeveloper
Archives
- Today
- Total
Jaebi의 Binary는 호남선
Swift Local Network Connection 본문
목차 Open
Preliminary
- iOS14 SDK 이상 -
Info.plist
에NSLocalNetworkUsageDescription
설정
NWConnection
- local endpoint와 remote endpoint를 연결하여 데이터 전송하는 객체
- initializer → NWEndpoint를 생성하고 NWParameters 지정
- NWEndpoint → network 연결의 local 또는 remote endpoint
hostPort
,service
(Bonjour Service),url
,unix
등 case로 서비스 Enpoint 지정
- NWParameters → network 경로 제약, 데이터 전송 옵션, 연결을 위해 사용되는 프로토콜 종류
tls
,tcp
,dtls
,udp
등
- NWEndpoint → network 연결의 local 또는 remote endpoint
- Connection 객체가 생성되면
stateUpdateHandler
로 connection 상태 확인 - connection 상태 handling 후
start
로 연결- Network 통신은 비동기로 이뤄져야 함으로 queue를 명시해줘야함
NSPathMonitor
- Network 변경을 monitoring하는 observer
pathUpdateHandler
를 통해 path interfaceType이wifi
/cellular
/wiredEthernet
/loopback
등 인지 알 수 있음
연결 후 send와 Receive
- connection state가 ready 되었을때
NWConnection.send(content: completion:)
- connection에 데이터 sendNWConnection.receiveMessage(completion:)
- 데이터 받을때 처리
Reference
NWConnection | Apple Developer Documentation
A bidirectional data connection between a local endpoint and a remote endpoint.
developer.apple.com
[Network] NWConnection
- 목적: 특정 프로그램의 UDP 포트 번호와 IP 주소 값을 통해, Data를 주고받을 수 있는 NWConnection을 이해한다. 우선, NWConnection이 뭐하는 객체인지 이해하자 NWConnection A bidirectional data connection between a
aviciiiphone.tistory.com
Network FrameWork를 이용한 HTTP 통신
HTTP 요청 실습을 하기 위해서 Swift Framework 중 하나인 Network를 사용해야 했는데 이에 대한 한글뿐 아니라 정리 문서가 너무 빈약해서 애 먹었다… 꽤나 최신에 나온 프레임워크인거 같기도 하고
ghis22130.github.io
'Swift' 카테고리의 다른 글
Swift - Memory 기초 (0) | 2024.07.20 |
---|---|
Swift - 문법 (접근 제어) (0) | 2024.07.20 |
Swift Wi-Fi Configuration (0) | 2024.06.19 |
WWDC 2024 - WeatherKit Sample App (0) | 2024.06.13 |
WeatherKit 사용 (WWDC 2024) (1) | 2024.06.13 |