本文整理汇总了C++中QTcpServer::errorString方法的典型用法代码示例。如果您正苦于以下问题:C++ QTcpServer::errorString方法的具体用法?C++ QTcpServer::errorString怎么用?C++ QTcpServer::errorString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTcpServer
的用法示例。
在下文中一共展示了QTcpServer::errorString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QTcpServer server;
if (!server.listen(QHostAddress::LocalHost, 49199)) {
qDebug("Failed to listen: %s", server.errorString().toLatin1().constData());
return 1;
}
#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
QFile file(QLatin1String("/test_signal.txt"));
file.open(QIODevice::WriteOnly);
file.write("Listening\n");
file.flush();
file.close();
#else
printf("Listening\n");
fflush(stdout);
#endif
server.waitForNewConnection(5000);
qFatal("Crash");
return 0;
}
示例2: HandleAcceptError
void QListenerThread::HandleAcceptError( QAbstractSocket::SocketError socketError )
{
QTcpServer* pServer =( QTcpServer* ) sender( );
Q_UNUSED( socketError )
QString strLog = pServer->errorString( );
SendLog( strLog, true );
}
示例3: proxyFactory
void tst_QTcpServer::proxyFactory()
{
QFETCH_GLOBAL(bool, setProxy);
if (setProxy)
return;
QFETCH(QList<QNetworkProxy>, proxyList);
QFETCH(QNetworkProxy, proxyUsed);
QFETCH(bool, fails);
MyProxyFactory *factory = new MyProxyFactory;
factory->toReturn = proxyList;
QNetworkProxyFactory::setApplicationProxyFactory(factory);
QTcpServer server;
bool listenResult = server.listen();
// Verify that the factory was called properly
QCOMPARE(factory->callCount, 1);
QCOMPARE(factory->lastQuery, QNetworkProxyQuery(0, QString(), QNetworkProxyQuery::TcpServer));
QCOMPARE(listenResult, !fails);
QCOMPARE(server.errorString().isEmpty(), !fails);
// note: the following test is not a hard failure.
// Sometimes, error codes change for the better
QTEST(int(server.serverError()), "expectedError");
}
示例4: listenError
//----------------------------------------------------------------------------------
void tst_QTcpServer::listenError()
{
QFETCH_GLOBAL(bool, setProxy);
if (setProxy) {
QFETCH_GLOBAL(int, proxyType);
if (proxyType == QNetworkProxy::Socks5Proxy) {
QSKIP("With socks5 we can not make hard requirements on the address or port", SkipAll);
}
}
QTcpServer server;
QVERIFY(!server.listen(QHostAddress("1.2.3.4"), 0));
QCOMPARE(server.serverError(), QAbstractSocket::SocketAddressNotAvailableError);
QCOMPARE(server.errorString().toLatin1().constData(), "The address is not available");
}
示例5: invalidProxy
void tst_QTcpServer::invalidProxy()
{
QFETCH_GLOBAL(bool, setProxy);
if (setProxy)
return;
QFETCH(int, type);
QFETCH(QString, host);
QFETCH(int, port);
QNetworkProxy::ProxyType proxyType = QNetworkProxy::ProxyType(type);
QNetworkProxy proxy(proxyType, host, port);
QTcpServer server;
server.setProxy(proxy);
bool listenResult = server.listen();
QVERIFY(!listenResult);
QVERIFY(!server.errorString().isEmpty());
// note: the following test is not a hard failure.
// Sometimes, error codes change for the better
QTEST(int(server.serverError()), "expectedError");
}
示例6: run
//*******************************************************************************
// Now that the first handshake is with TCP server, if the addreess/peer port of
// the client is already on the thread pool, it means that a new connection is
// requested (the old was desconnected). So we have to remove that thread from
// the pool and then connect again.
void UdpMasterListener::run()
{
mStopped = false;
QHostAddress PeerAddress; // Object to store peer address
int peer_udp_port; // Peer listening port
int server_udp_port; // Server assigned udp port
// Create and bind the TCP server
// ------------------------------
QTcpServer TcpServer;
if ( !TcpServer.listen(QHostAddress::Any, mServerPort) ) {
std::cerr << "TCP Socket Server ERROR: " << TcpServer.errorString().toStdString() << endl;
std::exit(1);
}
const int tcpTimeout = 5*1000;
cout << "JackTrip MULTI-THREADED SERVER: TCP Server Listening in Port = " << TcpServer.serverPort() << endl;
while ( !mStopped )
{
cout << "JackTrip MULTI-THREADED SERVER: Waiting for client connections..." << endl;
cout << "=======================================================" << endl;
while ( !TcpServer.waitForNewConnection(1000) )
{ if (mStopped) { return; } } // block until a new connection is received
cout << "JackTrip MULTI-THREADED SERVER: Client Connection Received!" << endl;
// Control loop to be able to exit if UDPs or TCPs error ocurr
for (int dum = 0; dum<1; dum++) {
QTcpSocket *clientConnection = TcpServer.nextPendingConnection();
if ( !clientConnection->waitForConnected(tcpTimeout) ) {
std::cerr << clientConnection->errorString().toStdString() << endl;
break;
}
PeerAddress = clientConnection->peerAddress();
cout << "JackTrip MULTI-THREADED SERVER: Client Connect Received from Address : "
<< PeerAddress.toString().toStdString() << endl;
// Get UDP port from client
// ------------------------
peer_udp_port = readClientUdpPort(clientConnection);
if ( peer_udp_port == 0 ) { break; }
cout << "JackTrip MULTI-THREADED SERVER: Client UDP Port is = " << peer_udp_port << endl;
// Check is client is new or not
// -----------------------------
// Check if Address is not already in the thread pool
// check by comparing 32-bit addresses
int id = isNewAddress(PeerAddress.toIPv4Address(), peer_udp_port);
// If the address is not new, we need to remove the client from the pool
// before re-starting the connection
if (id == -1) {
int id_remove;
id_remove = getPoolID(PeerAddress.toIPv4Address(), peer_udp_port);
// stop the thread
mJTWorkers->at(id_remove)->stopThread();
// block until the thread has been removed from the pool
while ( isNewAddress(PeerAddress.toIPv4Address(), peer_udp_port) == -1 ) {
cout << "JackTrip MULTI-THREADED SERVER: Removing JackTripWorker from pool..." << endl;
QThread::msleep(10);
}
// Get a new ID for this client
//id = isNewAddress(PeerAddress.toIPv4Address(), peer_udp_port);
id = getPoolID(PeerAddress.toIPv4Address(), peer_udp_port);
}
// Assign server port and send it to Client
server_udp_port = mBasePort+id;
if ( sendUdpPort(clientConnection, server_udp_port) == 0 ) {
clientConnection->close();
delete clientConnection;
releaseThread(id);
break;
}
// Close and Delete the socket
// ---------------------------
clientConnection->close();
delete clientConnection;
cout << "JackTrip MULTI-THREADED SERVER: Client TCP Socket Closed!" << endl;
// Spawn Thread to Pool
// --------------------
// Register JackTripWorker with the master listener
delete mJTWorkers->at(id); // just in case the Worker was previously created
mJTWorkers->replace(id, new JackTripWorker(this));
// redirect port and spawn listener
cout << "---> JackTrip MULTI-THREADED SERVER: Spawning Listener..." << endl;
{
QMutexLocker lock(&mMutex);
mJTWorkers->at(id)->setJackTrip(id, mActiveAddress[id][0],
server_udp_port, mActiveAddress[id][1],
1); /// \todo temp default to 1 channel
}
//send one thread to the pool
//.........这里部分代码省略.........