File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <esp_log.h>
2
+ #include <freertos/FreeRTOS.h>
3
+ #include <freertos/task.h>
4
+ #include <lwip/sockets.h>
5
+ #include <string.h>
6
+
7
+ #include "sdkconfig.h"
8
+
9
+ static char tag [] = "socketClient" ;
10
+
11
+ void socketClient (void * ignore ) {
12
+ ESP_LOGD (tag , "start" );
13
+ int sock = socket (AF_INET , SOCK_STREAM , IPPROTO_TCP );
14
+
15
+ ESP_LOGD (tag , "socket: rc: %d" , sock );
16
+ struct sockaddr_in serverAddress ;
17
+ serverAddress .sin_family = AF_INET ;
18
+ inet_pton (AF_INET , "192.168.1.200" , & serverAddress .sin_addr .s_addr );
19
+ serverAddress .sin_port = htons (9999 );
20
+
21
+ int rc = connect (sock , (struct sockaddr * )& serverAddress , sizeof (struct sockaddr_in ));
22
+ ESP_LOGD (tag , "connect rc: %d" , rc );
23
+
24
+ char * data = "Hello world" ;
25
+ rc = send (sock , data , strlen (data ), 0 );
26
+ ESP_LOGD (tag , "send: rc: %d" , rc );
27
+
28
+ rc = close (sock );
29
+ ESP_LOGD (tag , "close: rc: %d" , rc );
30
+
31
+ vTaskDelete (NULL );
32
+ }
You can’t perform that action at this time.
0 commit comments