C++ 尝试将Linux网络函数合并到Winsock程序中

C++ 尝试将Linux网络函数合并到Winsock程序中,c++,networking,winsock,C++,Networking,Winsock,我正在尝试将基于Linux的网络Tic-Tac-Toe程序的一部分实现到Winsock服务器程序中。Linux版本在整数变量中打开套接字时出现了一些问题: int-client\u-sock=0但是,在Winsock应用程序中会创建一个Csocket对象:m_pClientSocket=new Csocket() 现在很明显,当我试图编译将玩家移动到服务器的函数时: if (!SendStatus(client_sock, MOVE)) { ServerDisconnected(); }

我正在尝试将基于Linux的网络Tic-Tac-Toe程序的一部分实现到Winsock服务器程序中。Linux版本在整数变量中打开套接字时出现了一些问题:
int-client\u-sock=0但是,在Winsock应用程序中会创建一个Csocket对象:
m_pClientSocket=new Csocket()

现在很明显,当我试图编译将玩家移动到服务器的函数时:

if (!SendStatus(client_sock, MOVE)) { 
ServerDisconnected(); 
} 
我得到一个无效的变量类型错误,因为函数需要一个int,并且它正在接收一个Csock对象

我的问题是如何让函数工作?我已经尝试过获取套接字句柄并使用它,但我不确定这是否是正确的方向,并使用this
SendStatus(this->m_pClientSocket->GetSocketHandle(),WIN)给了我一些问题,因为它是一个静态函数

发送状态功能:

bool SendStatus(int socket, StatusCode status)
{
    char* data = (char*)&status;
    size_t left = sizeof(status);
    ptrdiff_t rc;

    while (left)
    {
        rc = send(socket, data + sizeof(status) - left, left, 0);
        if (rc <= 0) return false;
        left -= rc;
    }

    return true;
}
bool TakeTurn(TTTBoard& board)
{
    bool game_over = false;
    bool input_good = false;
    int row = 0, col = 0;

    // Display the board
    board.DrawBoard();

    while (!input_good)
    {
        printf("Enter move (row col): ");

        // Make sure two integers were inputted
        if (scanf_s("%d %d", &row, &col) == 2)
        {
            if (row < 0 || row > 2)
                printf("Invalid row input. Try again.\n");
            else if (col < 0 || col > 2)
                printf("Invalid column input. Try again.\n");
            else if (!board.IsBlank(row, col))
                printf("That cell isn't blank. Try again.\n");
            else
                input_good = true;
        }
        else
            printf("Invalid move input. Try again.\n");

        // flush any data from the internal buffers
        int c;
        while ((c = getchar()) != '\n' && c != EOF);
    }

    board.PlayerMakeMove(row, col);
    cout << "Sending move to server" << endl;

    // Send the move to the server
    if (!SendStatus(client_sock, MOVE))
        ServerDisconnected();

    if (!SendInt(client_sock, row))
        ServerDisconnected();

    if (!SendInt(client_sock, col))
        ServerDisconnected();

    // Check for win/draw
    if (board.IsWon())
    {
        cout << "YOU WIN!!!!" << endl;
        game_over = true;
        SendStatus(client_sock, WIN);
    }
    else if (board.IsDraw())
    {
        cout << "You tied ._." << endl;
        game_over = true;
        SendStatus(client_sock, DRAW);
    }

    return game_over;
}
bool SendStatus(int套接字,StatusCode状态)
{
字符*数据=(字符*)&状态;
左侧尺寸=尺寸(状态);
ptrdiff_t rc;
while(左)
{
rc=发送(套接字,数据+sizeof(状态)-left,left,0);
如果(rc 2)
printf(“行输入无效。请重试。\n”);
else if(col<0 | | col>2)
printf(“无效的列输入。请重试。\n”);
如果(!board.IsBlank(行,列))为空,则为else
printf(“该单元格不是空的。请重试。\n”);
其他的
输入_good=true;
}
其他的
printf(“无效的移动输入。请重试。\n”);
//从内部缓冲区刷新任何数据
INTC;
而((c=getchar())!='\n'&&c!=EOF);
}
棋盘游戏机移动(世界其他地区,哥伦比亚);

如果您在非Windows代码中使用的是最低级别的套接字,那么在移植到Windows时为什么不继续这样做呢?为什么要开始使用
CSocket
抽象?如果您想使用更高级别的类和抽象,我建议您找到一些独立于平台的套接字库来为您处理这部分代码,因为这应该只是在Windows上重新编译的问题。所以这不会像更改几行代码,或者添加两个函数那样简单?哈哈,这些程序的两个基础都不是我自己写的,但是我已经添加到它们中了。在完全写我自己的之前,我正在努力学习它们是如何工作的。如果你能给我解释一下插座的不同等级,或者给我指出正确的方向,我将不胜感激。