void exist(int sock, string msg){ string nickName (msg.begin() + 4, msg.end()); cout << nickName << endl; string response; if (conts.getSocketID(nickName) != -2){ response = "exs:true"; }else{ response = "exs:false"; } cout << response << endl; long sent = send(sock, &(response[0]), response.length(), 0); if (sent == -1) { perror("send"); } cout << "sent = " << sent << endl; }
void sendMessage(int sock, string msg){ char* pch = strtok(&(msg[0]), "\n"); string first (pch); pch = strtok(NULL, "\n"); if (pch == NULL) sendErrorMessage(sock,"snd has to have at least 3 lines"); string toWhom (pch); pch = strtok(NULL, ""); if (pch == NULL) sendErrorMessage(sock,"snd has to have at least 3 lines"); string message (pch); string fromWhom (first.begin()+4, first.end()); int socketToWhom = conts.getSocketID(toWhom); if (socketToWhom != -1) { cout << "sending message: " << toWhom << " " << fromWhom << " " << socketToWhom << " " << sock << endl; string parsedMessage = "snd:" + fromWhom + "\n" + message; if (send(socketToWhom, &(parsedMessage[0]), parsedMessage.length(), 0)) perror("send"); } }