【问题标题】:SFML TCP socket doesn't wait for dataSFML TCP 套接字不等待数据
【发布时间】:2015-05-15 17:49:26
【问题描述】:

代码在这里

#include <SFML/Network.hpp>
#include <iostream>

using namespace std;


int main(int argc, char* argv[]) {
    char mode = *argv[1];

    if(mode == (char) "-s") {
        sf::Packet recMessage;

        sf::TcpListener tcpListener;

        sf::TcpSocket inClient;

        tcpListener.accept(inClient);

        inClient.receive(recMessage);

        cout << recMessage << endl;
    }
}

当使用 -s 运行时,我希望程序在收到数据之前不会关闭,但是当我运行程序时它会关闭。

【问题讨论】:

  • 提示:mode == (char) "-s" 不正确,不会按照您的预期进行。使用std::strtmp 比较字符串。或者,你知道,使用std::string

标签: c++ network-programming sfml


【解决方案1】:

我将模式更改为 std::string 并取出 char 铸件

if 语句现在运行,如果我遇到任何问题,我会提出另一个问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    • 1970-01-01
    • 2012-11-04
    • 2017-01-17
    相关资源
    最近更新 更多