How can I send a command and Handle the command in c++ for listener.
I want something like the below code....
switch (args[i][1])
{
case 'command1':
command1function();
break;
case 'command2':
command2function();
break;
case 'command3':
command3function();
break;
default:
return 0;
}
TCP Listener c++ (Please see the GITHUB link this is not my project however I have been trying for hours now with no luck at all, Any help would be greatly appreciated) https://github.com/GreatBullet/Listener_Project/
void Class_tcp_Listener::Run()
{
char buf[MAX_BUFFER_SIZE];
while (true)
{
//create a listening socket
SOCKET listening = CreateSocket();
if (listening == INVALID_SOCKET)
{
break;
}
SOCKET client = WaitForConnection(listening);
if (client != INVALID_SOCKET)
{
closesocket(listening);
int bytesReceived = 0;
do
{
ZeroMemory(buf, MAX_BUFFER_SIZE);
bytesReceived = recv(client, buf, MAX_BUFFER_SIZE, 0);
if (bytesReceived > 0)
{
if (MessageReceived != NULL)
{
MessageReceived(this, client, std::string(buf, 0, bytesReceived));
std::cout << std::string(buf, 0, bytesReceived) << '\n';
}
}
} while (bytesReceived > 0);
closesocket(client);
}
}
}