我正在尝试通过 C 创建客户端/服务器,这是我的第一次 C 编程学习,我只想通过 localhost 进行连接,而不是通过互联网,我缺少什么。我该如何修复它并让我的服务器启动并运行,我应该输入什么来让我的客户端连接到我的服务器。
我需要创建一个可以与客户端发送和接收的服务器。对不起,我是 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