By the way this is one of my first UWP applications, but I know setting it in this function works because I had my Raspberry Pi connect to a TCP server (the one I copied and pasted to my win32 application) and it sent data fine and everything.
Used this command to allow through firewall:
Code: Select all
netsh advfirewall firewall add rule name="Open Port dddd" dir=in action=allow protocol=TCP localport=dddd
Code: Select all
Output: OK
Code: Select all
void StartupTask::Run(IBackgroundTaskInstance^ taskInstance)
{
WSADATA WsaData = { 0 };
WSAStartup(MAKEWORD(2, 2), &WsaData);
ADDRINFOW hints = { 0 }, *results = nullptr;
hints.ai_family = AF_INET;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
GetAddrInfoW(L"192.168.1.143", L"9000", &hints, &results);
SOCKET hSocket = socket(results->ai_family, results->ai_socktype, results->ai_protocol);
bind(hSocket, results->ai_addr, static_cast<int>(results->ai_addrlen));
listen(hSocket, 0);
char RecvBuffer[500];
SOCKET hConnection = INVALID_SOCKET;
hConnection = accept(hSocket, nullptr, nullptr);
while (true)
{
send(hConnection, "Hello!", 7, 0);
}
}