| 107 | } // namespace |
| 108 | |
| 109 | NetworkGame::NetworkGame(bool isServer) |
| 110 | { |
| 111 | m_bIsTcpServer = isServer; |
| 112 | setPerspectiveFlipped(!isServer); |
| 113 | m_tcpServer = NULL; |
| 114 | m_tcpSocket = NULL; |
| 115 | |
| 116 | QNetworkProxyFactory::setUseSystemConfiguration(false); |
| 117 | |
| 118 | initUI(); |
| 119 | |
| 120 | if(m_bIsTcpServer) //作为服务器端 |
| 121 | { |
| 122 | m_tcpServer = new QTcpServer(this); |
| 123 | onBtnTryConnect(); |
| 124 | connect(m_tcpServer, SIGNAL(newConnection()),this, SLOT(slotNewConnection())); |
| 125 | } |
| 126 | else //作为客户端 |
| 127 | { |
| 128 | m_tcpSocket = new QTcpSocket(this); |
| 129 | connect(m_tcpSocket, SIGNAL(readyRead()), this, SLOT(slotRecv())); |
| 130 | } |
| 131 | |
| 132 | connect(ChessBoard::ui->btnTcpConnect, &QPushButton::released, this, &NetworkGame::onBtnTryConnect); |
| 133 | connect(ChessBoard::ui->comboIp, &QComboBox::currentTextChanged, this, &NetworkGame::handleServerEndpointChange); |
| 134 | connect(ChessBoard::ui->sbPort, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &NetworkGame::handleServerEndpointChange); |
| 135 | } |
| 136 | |
| 137 | void NetworkGame::initUI() |
| 138 | { |
nothing calls this directly
no outgoing calls
no test coverage detected