{"action":"closed","issue":{"url":"https://api.github.com/repos/hassanyf/Simple-Server-and-Chat-Program/issues/6","repository_url":"https://api.github.com/repos/hassanyf/Simple-Server-and-Chat-Program","labels_url":"https://api.github.com/repos/hassanyf/Simple-Server-and-Chat-Program/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/hassanyf/Simple-Server-and-Chat-Program/issues/6/comments","events_url":"https://api.github.com/repos/hassanyf/Simple-Server-and-Chat-Program/issues/6/events","html_url":"https://github.com/hassanyf/Simple-Server-and-Chat-Program/issues/6","id":340850832,"node_id":"MDU6SXNzdWUzNDA4NTA4MzI=","number":6,"title":"[C++] xthread: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'","user":{"login":"vutuyetmai130398","id":29398905,"node_id":"MDQ6VXNlcjI5Mzk4OTA1","avatar_url":"https://avatars0.githubusercontent.com/u/29398905?v=4","gravatar_id":"","url":"https://api.github.com/users/vutuyetmai130398","html_url":"https://github.com/vutuyetmai130398","followers_url":"https://api.github.com/users/vutuyetmai130398/followers","following_url":"https://api.github.com/users/vutuyetmai130398/following{/other_user}","gists_url":"https://api.github.com/users/vutuyetmai130398/gists{/gist_id}","starred_url":"https://api.github.com/users/vutuyetmai130398/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vutuyetmai130398/subscriptions","organizations_url":"https://api.github.com/users/vutuyetmai130398/orgs","repos_url":"https://api.github.com/users/vutuyetmai130398/repos","events_url":"https://api.github.com/users/vutuyetmai130398/events{/privacy}","received_events_url":"https://api.github.com/users/vutuyetmai130398/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-13T01:30:52Z","updated_at":"2018-07-25T10:31:37Z","closed_at":"2018-07-25T10:31:37Z","author_association":"NONE","body":"`#include \"stdafx.h\"\r\n#include \"ServerType.h\"\r\n\r\nbool CheckResult(int iResult) {\r\n\tif (iResult) {\r\n\t\tcout << \"WSAStartup failed with error: \" << iResult<<endl;\r\n\t\treturn 0;\r\n\t}\r\n\treturn 1;\r\n}\r\n\r\nServerType::ServerType()\r\n{\r\n\tthis->iResult = WSAStartup(MAKEWORD(2, 2), &this->wsaData);\r\n\tthis->addrin.result = NULL;\r\n\tthis->recvbuf = new char[DEFAULT_BUFLEN];\r\n\tthis->recvbuflen = DEFAULT_BUFLEN;\r\n\tthis->_client = INVALID_SOCKET;\r\n\tthis->_server = INVALID_SOCKET;\r\n}\r\n\r\n\r\nbool ServerType::InitWinSock()\r\n{\r\n\tif (CheckResult(this->iResult)) {\r\n\t\tZeroMemory(&this->addrin.hints, sizeof(this->addrin.hints));\r\n\t\tthis->addrin.hints.ai_family = AF_INET;\r\n\t\tthis->addrin.hints.ai_socktype = SOCK_STREAM;\r\n\t\tthis->addrin.hints.ai_protocol = IPPROTO_TCP;\r\n\t\tthis->addrin.hints.ai_flags = AI_PASSIVE;\r\n\r\n\t\tthis->iResult = getaddrinfo(NULL, DEFAULT_PORT, &this->addrin.hints, &this->addrin.result);\r\n\t\tif (this->iResult) {\r\n\t\t\tcout << \"Getaddrinfo failed with error: \" << this->iResult<<endl;\r\n\t\t\tWSACleanup();\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\treturn 1;\r\n\t}\r\n\treturn false;\r\n}\r\n\r\nbool ServerType::ConnectServer()\r\n{\r\n\t//Create a SOCKET for connecting server\r\n\tthis->_server = socket(this->addrin.result->ai_family, this->addrin.result->ai_socktype, this->addrin.result->ai_protocol);\r\n\r\n\tif (this->_server == INVALID_SOCKET) {\r\n\t\tcout << \"Socket failed with error: \" << WSAGetLastError() << endl;\r\n\t\tfreeaddrinfo(this->addrin.result);\r\n\t\tWSACleanup();\r\n\t\treturn 0;\r\n\t}\r\n\r\n\tcout << \"Binding socket ...\" << endl;\r\n\tbind(this->_server, this->addrin.result->ai_addr, (int)this->addrin.result->ai_addrlen);\r\n\t\r\n\tfreeaddrinfo(this->addrin.result);\r\n\r\n\tthread thdReceive(&ServerType::ListenClient, this);\r\n\tthdReceive.detach();\r\n\treturn false;\r\n}\r\n\r\nvoid ServerType::ListenClient()\r\n{\r\n\ttry\r\n\t{\r\n\t\twhile (1) {\r\n\t\t\tlisten(this->_server, SOMAXCONN);\r\n\t\t\tSOCKET client = INVALID_SOCKET;\r\n\t\t\tclient = accept(this->_server, NULL, NULL);\r\n\r\n\t\t\tif (client == INVALID_SOCKET) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\telse {\r\n\t\t\t\tthis->_clientList.push_back(client);\r\n\t\t\t\tthread ReceiveThr(&ServerType::ReceiveMsg, std::ref(client));\r\n\t\t\t\tReceiveThr.detach();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tcatch (const std::exception&)\r\n\t{\r\n\r\n\t}\r\n}\r\n\r\nvoid ServerType::ReceiveMsg(SOCKET client)\r\n{\r\n\tstring msg = \"\";\r\n\r\n\twhile (true)\r\n\t{\r\n\t\tmemset(this->recvbuf, 0, DEFAULT_BUFLEN);\r\n\r\n\t\tif (client != INVALID_SOCKET) {\r\n\t\t\tthis->iResult = recv(client, this->recvbuf, DEFAULT_BUFLEN, 0);\r\n\r\n\t\t\tif (this->iResult != SOCKET_ERROR) {\r\n\t\t\t\tif (strcmp(\"\", this->recvbuf)) {\r\n\t\t\t\t\tmsg = this->recvbuf;\r\n\t\t\t\t\tcout << msg << endl;\r\n\t\t\t\t\tfor (std::vector<SOCKET>::iterator it = this->_clientList.begin(); it != this->_clientList.end(); it++) {\r\n\t\t\t\t\t\tif (*it != INVALID_SOCKET && *it!=client) {\r\n\t\t\t\t\t\t\tthis->iResult = send(*it, msg.c_str(), strlen(msg.c_str()), 0);\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tmsg = \"Client Disconnect!!\\n\";\r\n\t\t\t\tcout << msg;\r\n\t\t\t\tfor (std::vector<SOCKET>::iterator it = this->_clientList.begin(); it != this->_clientList.end(); it++) {\r\n\t\t\t\t\tif (*it == client) {\r\n\t\t\t\t\t\tclosesocket(*it);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (*it != INVALID_SOCKET) {\r\n\t\t\t\t\t\tthis->iResult = send(*it, msg.c_str(), strlen(msg.c_str()), 0);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t\tclosesocket(client);\r\n\t\t\t}\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\t\r\n}\r\n\r\nServerType::~ServerType()\r\n{\r\n}\r\n`\r\ni have a project which is used \"Chat app\" written by C++. But i have some problems in the xthread file, I cannot fix them, I use \"this\" in the \"thread\" function, but it not successful. \r\nPlease help me!"}}
{"actor":{"display_login":"hassanyf"}}