0
私は小さなネットワークベースのチェスアプリケーションに取り組んできました。私は複数の接続を処理できるサーバーを作成することができましたが、クライアントから別のクライアントにデータを送信する方法はわかりません。winsockを使ったマルチスレッドチェス
はここでゲームの両方のプレイヤーがサーバーに接続されている場合たぶん、あなたは新しいゲームのためのスレッドを開始すべき部分Serverの実装
//function to handle our Socket on its own thread.
//param- SOCKET* that is connected to a client
DWORD WINAPI HandleSocket(void* param)
{
string test;
SOCKET s = (SOCKET)param;
User temp;
temp._socket = (SOCKET)param;
temp._inGame = false;
userlist.add(&temp);
std::cout<<"connection"<<endl;
int bytesread = 0;
int byteswrite=0;
while(true)
{
//receive
bytesread = recv(s, reinterpret_cast<char*>(test.c_str()), BUF_LEN, 0);
//error check
if(bytesread == SOCKET_ERROR)
{
std::cout << WSAGetLastError();
//shutdown and close on error
shutdown(s, SD_BOTH);
closesocket(s);
return 0;
}
//check for socket being closed by the client
if(bytesread == 0)
{
//shutdown our socket, it closed
shutdown(s, SD_BOTH);
closesocket(s);
return 0;
}
byteswrite = send(s, "test" , 255 , 0);
if(byteswrite == SOCKET_ERROR)
{
std::cout << WSAGetLastError();
//shutdown and close on error
shutdown(s, SD_BOTH);
closesocket(s);
return 0;
}
test.clear();
}
}
recvの第2引数としてtest.c_str()をキャストして、何を達成したいと考えていますか? –