1

我正在尝试使用 VMCI 套接字在虚拟机与其主机之间建立面向流的连接。我成功启动服务器,绑定地址,进入监听模式,调用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");

每当我使用数据报套接字时,问题都不存在。(当然,无需调用listen、accept 和connect。在这种情况下,我只需使用sendto(...)which 就可以了。)

4

1 回答 1

0

VMware 文档中,我刚刚发现:

在 Workstation 7.0 中,Linux 主机、Linux 来宾和 Windows 来宾支持流套接字,但 Windows 主机仅支持数据报套接字。

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

于 2013-03-20T13:26:17.930 回答