単純なソケット接続を作成しようとしています。
これは私のクライアントがやっていることです:
strcpy(send_data, "Hello Server");
send(sock,send_data,strlen(send_data), 0);
strcpy(send_data, "Compression Method: null(0)");
send(sock,send_data,strlen(send_data), 0);
strcpy(send_data, "end");
send(sock,send_data,strlen(send_data), 0);
send_data
と定義されているchar send_data[1024]
ここに私のサーバー側があります:
int clntSock = accept(servSock, (struct sockaddr *) &clntAddr, &clntAddrLen);
while(clntSock){
int inMsgLen = recvfrom(clntSock, inMsg, 1024, 0,(struct sockaddr *)&clntAddr, (socklen_t*)&clntAddrLen);
inMsg[inMsgLen] = '\0';
if(strcmp(inMsg, "Hello Server") == 0){ // check if the client sent hello server
printf("%s\n", inMsg);
} else if(strcmp(inMsg, "end") == 0){ // check if client send end
printf("\n WHY ISNT"T THIS EXECUTING\n"); // THIS IS NOT HAPPENING
} else {
printf("%s\n", inMsg); //keep receiving and do nothing
}
これで、私のサーバーは最初のチェック (つまり、クライアントがサーバーの hello を送信したかどうかのチェック) を実行し、これを出力します:Hello Server
それからelseステートメントに行き、出力します:Compression Method: null(0)
その後、elseステートメントに入り続けます... else ifステートメントを実行することはありません
* else_if ステートメントが実行されないのはなぜですか?*