0
私は通常C言語で何も書いていません。私は教科書のコードを試していますが、それは私にエラーを与えています。クライアントとサーバーの実行可能ファイルをコンパイルしました。私はサーバー./serverとクライアント./client localhostを実行します。クライアントを実行するたびに、サーバを含む端末は、シンプレックストーク:accept:無効な引数を表示します。私はどこかで、議論は「価値のある結果の議論」であるかもしれないと読んだ。私はこれが何を意味し、どのようにこれに当てはまるかを知らない。ここでは、コードは次のようになります。simplex-talk:accept:単純なソケットプログラムで無効な引数エラーです。
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <cstdlib>
#include <cstdio>
#include <unistd.h>
#include <strings.h>
#include <string.h>
#
#define SERVER_PORT 20169
#define MAX_PENDING 5
#define MAX_LINE 256
int
main()
{
struct sockaddr_in sin;
char buf[MAX_LINE];
socklen_t len;
int s, new_s;
/* build address data structure */
memset((char *)&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(SERVER_PORT);
/* setup passive open */
if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
perror("simplex-talk: socket");
exit(1);
}
if ((bind(s, (struct sockaddr *)&sin, sizeof(sin))) < 0) {
perror("simplex-talk: bind");
exit(1);
}
listen(s, MAX_PENDING);
/* wait for connection, then receive and print text */
while(1) {
if ((new_s = accept(s, (struct sockaddr *)&sin, &len)) < 0) {
perror("simplex-talk: accept");
exit(1);
}
while (len = recv(new_s, buf, sizeof(buf), 0))
fputs(buf, stdout);
close(new_s);
}
}
リスニングの戻り値を確認してエラーが発生していないかどうか確認してみましたか? – Jay