私は以下のようにしています。サーバーがListenするためのソケットが作成されているコンストラクタを開始します。 (バインディング、リスニングなど) 次に、クライアントからの着信コールを受け付ける必要がある着信コールを検索する関数を開始するThreadを生成します。 接続したソケットをリストに入れる必要があります。 その後、新しいスレッドが作成されています。C++スレッド/ベクトルチャット
しかし、彼はクライアントの受け入れに立ち往生し、私は本当にそれを調べました。 たくさんお願いします。
First-chance exception at 0x010820b1 in ChatServer.exe: 0xC0000005: Access violation reading location 0x00000000. Unhandled exception at 0x010820b1 in ChatServer.exe: 0xC0000005: Access violation reading location 0x00000000.
それはmuch-ビットです> ServerCode:
int main(int argc, char* argv[])
{
//Constructor that takes care of making connection
//Throw in a new Thread
CreateThread(0,0,&ServerListenThread,0,0,0);
//while loop to get input and pass it to the SendMessages function
//function being called within a Thread
DWORD WINAPI ServerListenThread(LPVOID pParam)
{
while(1)
CServerObj->StartListenClient();
return 0;
}
void CServer::StartListenClient()
{
sockaddr_in i_addr;
int i_addrlen = sizeof(i_addr);
SocketC = accept(SocketS,(struct sockaddr*)&i_addr,&i_addrlen); <<<Here it gives the Access Violation< at the accept
{
cout << "A Connection was found with :" <<endl;
}
SocketS = SocketC;
if(SocketS != INVALID_SOCKET)
{
vClientList.push_back(SocketS);
CreateThread(0,0,&ServerRecThread, (void*)SocketS, 0,0);
}
}
デバッグモードでコールスタックを確認して、ここにポストできますか? _Insideが失敗したという情報を投稿しただけですが、この_Insideと呼ばれるコードのどの部分が面白いですか。 – Zuljin
CServer :: SendMessagesのforループの終了条件が原因である可能性があります。itl!= vClientVector.end()を使用すると、より小さい演算子がここで予測できない結果を生成しています。 – Jack