It seems to be related to the quick close of the socket after sendto in the UDP client. If you wait for a while and then close the socket again, this problem will not occur.
//
// main.cpp
//
#include <iostream>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
int main(int argc, const char * argv[])
{
// arg check
int nLocalPort = -1;
const char *lpcszRemoteIP = "192.168.1.123";
int nRemotePort = 12345;
const char *lpcszData = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (argc > 1)
{
// arg 1
lpcszRemoteIP = argv[1];
if (argc > 2)
{
const char *lpcszRemotePort = argv[2];
nRemotePort = atoi(lpcszRemotePort);
if (argc > 3)
{
const char *lpcszLocalPort = argv[3];
nLocalPort = atoi(lpcszLocalPort);
if (argc > 4)
{
lpcszData = argv[4];
}
}
}
}
size_t stDataSize = strlen(lpcszData) * sizeof(char);
printf("Role : UDP Client\n");
if (nLocalPort != -1)
printf("Local : local:%d\n", nLocalPort);
printf("Remote: %s:%d\n", lpcszRemoteIP, nRemotePort);
printf("Data : [%ld]%s\n", stDataSize, lpcszData);
int nSocket = -1;
do
{
nSocket = socket(AF_INET, SOCK_DGRAM, 0);
if (nSocket == -1)
{
printf("socket() == -1\n");
break;
}
if (nLocalPort != -1)
{
struct sockaddr_in addrLocal;
addrLocal.sin_family = AF_INET;
addrLocal.sin_port = htons(nLocalPort);
addrLocal.sin_addr.s_addr = htonl(INADDR_ANY);
int nBind = bind(nSocket, (const struct sockaddr *)&addrLocal, sizeof(addrLocal));
if (nBind != 0)
{
printf("bind(%d) error. ret: %d errno: %d\n", nLocalPort, nBind, errno);
break;
}
else
{
printf("bind(%d)\n", nLocalPort);
}
}
struct sockaddr_in addrServer;
addrServer.sin_family = AF_INET;
addrServer.sin_port = htons(nRemotePort);
if (inet_pton(AF_INET, lpcszRemoteIP, &addrServer.sin_addr.s_addr) != 1)
{
printf("inet_pton() != 1\n");
break;
}
// Send Data
ssize_t nSend = sendto(nSocket, lpcszData, stDataSize, 0, (const struct sockaddr *)&addrServer, sizeof(addrServer));
if (nSend < stDataSize)
{
printf("sendto() error. ret: %ld errno: %d\n", nSend, errno);
}
} while (false);
/*
int nTime = 0;
while (true)
{
sleep(1);
nTime++;
if (nTime >= 5)
break;
}
*/
if (nSocket != -1)
{
close(nSocket);
nSocket = -1;
}
return 0;
}
How should it be dealt with in [MyTransparentProxyProvider handleNewFlow:] or [MyTransparentProxyProvider handleNewUDPFlow:initialRemoteEndpoint:]?Perhaps when The error "The peer closed the flow" occurs in [NEAppProxyUDPFlow openWithLocalEndpoint:completionHandler:], should the Network Extension take over this flow instead of returning NO?