gpt4 book ai didi

连接 VMCI 流套接字

转载 作者:行者123 更新时间:2023-11-30 17:53:57 24 4
gpt4 key购买 nike

我正在尝试使用 VMCI 套接字在虚拟机与其主机之间建立面向流的连接。我成功启动服务器,绑定(bind)地址,将其置于监听模式,并调用accept等待客户端。但是,每当我从客户端调用 connect(...) 时,都会收到 WSAECONNRESET 错误。

我的客户端代码是:

int sockfd;    
WSADATA wsaData;
WORD wVersionRequested = MAKEWORD(2, 2);

// initialize sockets for win32
if (WSAStartup(wVersionRequested, &wsaData) != 0) {
perror("Could not register with Winsock DLL.\n");
exit(-1);
}

// get VMCI socket file descriptor
int afVMCI = VMCISock_GetAFValue();
if ((sockfd = socket(afVMCI, SOCK_STREAM, 0)) == -1) {
perror("socket");
exit(-1);
}

// initialize server address
struct sockaddr_vm their_addr = {0};
their_addr.svm_family = afVMCI;
their_addr.svm_cid = 2;
their_addr.svm_port = 1234;

// connect to server
if ((connect(sockfd, (struct sockaddr *) &their_addr, sizeof(their_addr))) == -1) {
int e = WSAGetLastError();
printf("Error: %d\n", e);
exit(-1);
}

printf("Connected!\n");

每当我使用数据报套接字时,问题就不会出现。 (当然,无需调用监听、接受和连接。在这种情况下,我只需使用 sendto(...) 即可正常工作。)

最佳答案

来自VMware documentation ,我刚刚发现:

In Workstation 7.0, stream sockets were supported for Linux hosts, Linux guests, and Windows guests, but only datagram sockets were supported for Windows hosts.

由于我的主机运行 Windows,因此不支持此功能。

关于连接 VMCI 流套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15343491/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com