NB-IoT学习笔记:四、连接TCP服务器并传输数据

文章目录

  • 1.创建Socket
  • 2.连接TCP服务器
  • 3.发送数据,仅限 TCP
  • 3.接收服务器数据
  • 4.关闭Socket,断开连接

1.创建Socket

/* Use AT+NSOCR to create a socket on the UE and associates with specified protocol */
[2020-06-21 10:55:56:040_S:] AT+NSOCR=STREAM,6,0,1
[2020-06-21 10:55:56:160_R:] AT+NSOCR=STREAM,6,0,1
[2020-06-21 10:55:56:160_R:] 1

[2020-06-21 10:55:56:160_R:] OK

2.连接TCP服务器

[2020-06-21 10:55:58:214_S:] AT+NSOCO=1,47.105.44.99,1001
[2020-06-21 10:55:58:349_R:] AT+NSOCO=1,47.105.44.99,1001
[2020-06-21 10:55:58:349_R:] OK

3.发送数据,仅限 TCP

[2020-06-21 10:56:06:891_S:] AT+NSOSD=1,4,54455354
[2020-06-21 10:56:07:012_R:] AT+NSOSD=1,4,54455354
[2020-06-21 10:56:07:012_R:] 1,4

[2020-06-21 10:56:07:012_R:] OK

3.接收服务器数据

[2020-06-15 09:58:26:871_R:] +NSONMI:1,9
[2020-06-15 09:58:26:871_S:] AT+NSORF=1,9
[2020-06-15 09:58:27:004_R:] AT+NSORF=1,9
[2020-06-15 09:58:27:004_R:] 1,47.105.44.99,1001,9,544553545F52454356,0

[2020-06-15 09:58:27:037_R:] OK

4.关闭Socket,断开连接

/* Use AT+NSOCL to close the connection of UDP */
[2020-06-15 09:53:00:493_S:] AT+NSOCL=1
[2020-06-15 09:53:00:557_R:] AT+NSOCL=1
[2020-06-15 09:53:00:557_R:] OK

你可能感兴趣的:(NB-iot笔记)