![Mediatek Labs LinkIt Connect 7681 Скачать руководство пользователя страница 50](http://html1.mh-extra.com/html/mediatek-labs/linkit-connect-7681/linkit-connect-7681_developers-manual_1760804050.webp)
MediaTek LinkIt™ Connect 7681 Developer's Guide
© 2015, 2016 MediaTek Inc.
Page 45 of 65
This document contains information that is proprietary to MediaTek Inc.
Unauthorized reproduction or disclosure of this information in whole or in part is strictly prohibited.
5.3.1.
Creating a TCP client that connects to a remote TCP server
This section describes how to create a TCP client, connect to a remote TCP server and exchange
data with that remote server.
1)
Initialize the connection
Use
uip_connect()
to create the connection. In the example below, a connection to port
9999 of 192.168.1.1 with the local port is set as 8888 is defined:
File: iot_tcp_app.c
void
app_init_connection
(
void
)
{
UIP_CONN
*
tcp_conn
=
NULL
;
uip_ipaddr_t raddr
;
UINT8 iot_srv_ip
[
MAC_IP_LEN
]
=
{192, 168, 1, 1}
;
uip_ipaddr
(
raddr
,
iot_srv_ip
[
0
],
iot_srv_ip
[
1
],
iot_srv_ip
[
2
],
iot_srv_ip
[
3
]);
/* Specify remote address and port here. */
tcp_conn
=
uip_connect
(&
raddr
,
HTONS
(
9999
));
if
(
tcp_conn
)
{
tcp_conn
->
lport
=
HTONS
(
8888
);
}
else
{
printf_high
(
"connect fail\n"
);
}
}
This step can be actioned at any time, including before MT7681 has connected to a wireless
network.