PC or Smartphone is tcp client and CC3200 is tcp server in AP mode.
Socket connection succeeded and client send packets to server.
Through a sl_Recv() function, I can received packets very well.
But the client disconnect to server, there isn't any return values from sl_Recv().
It's polling on sl_Recv(). When the client attempt to reconnect server, sl_Recv() return error value and then it's can't connect to server.
How can a client reconnect to server?
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
char received_data[100];
//filling the TCP server socket address
sLocalAddr.sin_family = SL_AF_INET;
sLocalAddr.sin_port = sl_Htons((unsigned short)5001);
sLocalAddr.sin_addr.s_addr = 0;
// creating a TCP socket
iSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
if( iSockID < 0 )
{
// error
ASSERT_ON_ERROR(SOCKET_CREATE_ERROR);
}
iAddrSize = sizeof(SlSockAddrIn_t);
// binding the TCP socket to the TCP server address
iStatus = sl_Bind(iSockID, (SlSockAddr_t *)&sLocalAddr, iAddrSize);
if( iStatus < 0 )
{
// error
sl_Close(iSockID);
ASSERT_ON_ERROR(BIND_ERROR);
}
// putting the socket for listening to the incoming TCP connection
iStatus = sl_Listen(iSockID, 0);
if( iStatus < 0 )
{
sl_Close(iSockID);
ASSERT_ON_ERROR(LISTEN_ERROR);
}
// setting socket option to make the socket as non blocking
iStatus = sl_SetSockOpt(iSockID, SL_SOL_SOCKET, SL_SO_NONBLOCKING,
&lNonBlocking, sizeof(lNonBlocking));
if( iStatus < 0 )
{
sl_Close(iSockID);
ASSERT_ON_ERROR(SOCKET_OPT_ERROR);
}
for(;;)
{
iNewSockID = SL_EAGAIN;
// waiting for an incoming TCP connection
while( iNewSockID < 0 )
{
// accepts a connection form a TCP client, if there is any
// otherwise returns SL_EAGAIN
iNewSockID = sl_Accept(iSockID, ( struct SlSockAddr_t *)&sAddr,
(SlSocklen_t*)&iAddrSize);
if( iNewSockID == SL_EAGAIN )
{
//MAP_UtilsDelay(10000);
osi_Sleep(1);
}
else if( iNewSockID < 0 )
{
// error
sl_Close(iNewSockID);
ASSERT_ON_ERROR(ACCEPT_ERROR);
}
}
for(;;)
{
//received packets from the connected TCP client
iStatus = sl_Recv(iNewSockID, received_data, 100, 0);
if( iStatus < 0 )
{
//error
sl_Close(iNewSockID);
ASSERT_ON_ERROR(ACCEPT_ERROR);
break;
}
else if( iStatus > 0 )
{
received_data[iStatus] = 0;
UART_PRINT("Received Data: %s\n\r",received_data);
}
else
{
sl_Close(iNewSockID);
break;
}
}
}
|
cs |