TCP/UDP 통신연습
TCP/UDP is used to setup connections between clients and servers, which are used for TCP/UDP clients communicating with servers.
Example TCP Echo Server:
TCP Echo server | Description | IP | Port |
echo.mbedcloudtesting.com | 52.215.34.155 | 7 | |
tcpbin.com (“https://tcpbin.com/” to get certificate) |
45.79.112.203 | 4242 | |
Echo with TLS encryption | 45.79.112.203 | 4243 | |
Echo with mutual authentication | 45.79.112.203 | 4244 |
1. TCP/UPD 통신 설정과정
2. TCP/UPD 통신 명령시퀀스
NO | Command | Response | 설명 |
1 | PDP Context 설정 | ||
2 | AT+CIPMODE? |
+CIPMODE: 0 OK |
TCP/UDP Data Mode 확인 (Non-Transparent Data Mode로 설정됨) |
AT+CIPMODE=<mode> |
+CIPMODE: 0 OK |
Data Mode 설정 | |
3 | AT+NETOPEN |
OK +NETOPEN: 0 |
(1) PDP Context 활성화 (2) TCP/UDP 서비스 시작 |
AT+NETOPEN? |
OK +NETOPEN: 1 |
TCP/UDP 서비스상태 확인 | |
AT+IPADDR |
+IPADDR: 10.17.88.228 OK |
Networks에서 할당된 IP 확인 | |
4 | AT+CIPRXGET? |
+CIPRXGET: 0 OK |
Data RX Mode 확인 |
AT+CIPRXGET=0 | OK | Data RX Mode 설정 | |
5 | AT+CIPOPEN=0,”TCP”,”yahoo.com”,80 | +CIPOPEN: 0,0 | TCP/UDP Socket 연결 설정 |
– | AT+CIPOPEN? |
+CIPOPEN: 0,”TCP”,”74.6.231.21″,80,-1 +CIPOPEN: 1 +CIPOPEN: 2 +CIPOPEN: 3 +CIPOPEN: 4 +CIPOPEN: 5 +CIPOPEN: 6 +CIPOPEN: 7 +CIPOPEN: 8 +CIPOPEN: 9 OK |
|
6.1 | AT+CIPSEND=0,34 | > | TCP/UDP 데이터 송신 설정 |
6.2 | >\r\n GET https://yahoo.com/ip HTTP/1.0\r\n | 송신 데이터 입력(HTTP Get 메소드) | |
AT+CIPSEND=0, | > | ||
>123456789\x03\r\n\x1A\r\n |
<ETX> = \x03\r\n <CTRL+Z> = \x1A\r\n |
||
+++ | Transparent Mode 인 경우, 탈출 | ||
7 | AT+CIPCLOSE=0 |
+CSQ: 28,99 OK |
소켓 종료 |
8 | AT+NETCLOSE |
OK +NETCLOSE: 0 |
TCP/UDP 서비스 종료 |