I am trying to create a thread in order to send a message to an open socket. I am gettings 2 specific errors.
E0289: No instance of constructor "std::thread::thread" matches the argument list.
C2661: 'std::thread::thread' no overloaded function takes 2 arguments**
I have found similar posts about this but still cannot quite figure it out could really use some clarification.
#include <WS2tcpip.h>
#include <string>
#include <thread>
using namespace std;
#pragma comment (lib, "ws2_32.lib")
void SendMessage(string message)
{
WSAData data;
WORD version = MAKEWORD(2, 2);
int wsOk = WSAStartup(version, &data);
if (wsOk != 0)
{
cout << "Failed, Error Code: " << WSAGetLastError() << endl;
}
sockaddr_in user;
user.sin_family = AF_INET;
user.sin_port = htons(3514);
inet_pton(AF_INET, "127.0.0.1", &user.sin_addr);
SOCKET out = socket(AF_INET, SOCK_DGRAM, 0);
int sendMsg = sendto(out, message.c_str(), message.size() + 1, 0, (sockaddr*)&user, sizeof(user));
if (sendMsg == SOCKET_ERROR)
{
cout << "Failed, Error: " << WSAGetLastError() << endl;
}
closesocket(out);
WSACleanup();
}
int main()
{
string message = "";
cout << "Enter a message to send: ";
cin >> message;
thread sendtoSocket (SendMessage, message);
sendtoSocket.join();
system("pause");
return 0;
}