私はCでクライアント/サーバーを作成しようとしています。これは私の最初のCプログラミング学習であり、インターネットではなくローカルホストのみで接続を行いたいのですが、何が欠けていますか。それを修正してサーバーを稼働させるにはどうすればよいですか。また、クライアントをサーバーに接続するには何を入力すればよいですか。
クライアントと送受信できるサーバーを作成する必要があります。申し訳ありませんが、私はCプログラミングを初めて使用します。学習段階にありますが、経験不足をご容赦ください。ここで専門家から学びたいと思っています。
以下はメインの私のコードです
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/un.h>
#include <sys/types.h>
#include <sys/socket.h>
using namespace std;
int main()
{
int serverFd;
int clientFd;
struct sockaddr_un serverAddress;
cout << "" << endl;
cout << "Running server program 'css' ...... " << endl;
cout << "" << endl;
// SOCKET CREATION PART - SERVER
serverFd = socket (AF_LOCAL, SOCK_STREAM, 0);
/* Set domain type */
serverAddress.sun_family = AF_LOCAL;
/* Set name */
strcpy (serverAddress.sun_path, "Server");
/* Remove file if it already exists */
unlink ("Server");
/* Create file */
bind (serverFd, serverSockAddrPtr, serverLen);
// SOCKET CREATION END - SERVER
return 0;
}
私が得るエラー:
CountryServer.c:39:17: error: ‘serverSockAddrPtr’ was not declared in this scope
CountryServer.c:39:36: error: ‘serverLen’ was not declared in this scope