相关疑难解决方法(0)

在窗户中替代分叉

我一直在关注Beej Networking指南,在服务器部分,有一部分代码叫做函数fork().

if (!fork()) { // this is the child process
            close(sockfd); // child doesn't need the listener
            if (send(new_fd, "Hello, world!", 13, 0) == -1)
                perror("send");
            close(new_fd);
            exit(0);
Run Code Online (Sandbox Code Playgroud)

我在Windows机器上,不能让那部分工作.我能做些什么来解决这个问题?我的代码如下.

/* Server */
#define _WIN32_WINNT 0x501
#include <iostream>
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include  <sys/types.h>


using namespace std;

const int winsockVersion = 2;
#define BACKLOG 10
#define PORT "3000"


int main(void){

    WSADATA wsadata;
    if (WSAStartup(MAKEWORD(winsockVersion,0),&wsadata) == 0){
        cout<<"-WSAStartup initialized..." << endl;

        int status;
        int sockfd, …
Run Code Online (Sandbox Code Playgroud)

c++ winapi gcc fork winsock

13
推荐指数
3
解决办法
2万
查看次数

标签 统计

c++ ×1

fork ×1

gcc ×1

winapi ×1

winsock ×1