Original Post
I'm trying to send a std::vector of two elements to the client using the winsock sendto() function like so: what I want is to get the vector of two elements to the client like so: Is the way to typecast a char * to std::vector?
// it's a seeking message. send a reply now
CMessageHosting msgHost;
int iCMHostSize = 0;
static std::vector<CMessageHosting> cmHostList;
msgHost.SetUsername(phUsername);
msgHost.SetHostname(phHostname);
msgHost.SetNumClients((unsigned)pClientList->size());
cmHostList.push_back(msgHost);
iCMHostSize = (int)cmHostList.size() * sizeof(CMessageHosting);
std::cout<<"Receiving a seek from "<<
((CMessageSeeking*)pCMsg)->GetUsername()<<
"@"<<GetHostDescription(rSockAddr)<<std::endl;
// send the host response back to the sender
result = sendto(rSocket, (char *)&cmHostList, iCMHostSize,
0, (const sockaddr *)&rSockAddr, nSALen);
if(result == SOCKET_ERROR)
CheckWSAError("sending a replay to a seek");
else
bDone = true;
while(!bStop)
{
char receiveMsg[MAX_MESSAGE_LEN] = {0};
iResult = recvfrom(hClientSocket, receiveMsg, MAX_MESSAGE_LEN, 0,
(sockaddr *)&saFrom, &iFromLen);
if(iResult == SOCKET_ERROR)
CheckWSAError(" recvfrom ");
else
{
//CMessage *pMsg = (CMessage *)receiveMsg;
std::vector<CMessage*> *cmList = 0;
cmList = (std::vector<CMessage*> *)receiveMsg;
bUpdateDisplay = SeekMessageHosts(&hostList, cmList,
nID, dwLoopTime, saFrom);
bStop = true;
}
}