本文整理汇总了C++中QTcpSocket::abort方法的典型用法代码示例。如果您正苦于以下问题:C++ QTcpSocket::abort方法的具体用法?C++ QTcpSocket::abort怎么用?C++ QTcpSocket::abort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTcpSocket
的用法示例。
在下文中一共展示了QTcpSocket::abort方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stopListening
void ApiServer::stopListening()
{
DEBUG_LOW_LEVEL << Q_FUNC_INFO;
// Closes the server. The server will no longer listen for incoming connections.
close();
m_lockedClient = NULL;
emit updateDeviceLockStatus(Api::DeviceUnlocked);
QMap<QTcpSocket*, ClientInfo>::iterator i;
for (i = m_clients.begin(); i != m_clients.end(); ++i)
{
QTcpSocket * client = dynamic_cast<QTcpSocket*>(i.key());
disconnect(client, SIGNAL(readyRead()), this, SLOT(clientProcessCommands()));
disconnect(client, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
client->abort();
client->deleteLater();
}
m_clients.clear();
}
示例2: sendBase
void MT500::testConnection()
{
for(int i = 0; i < 6; i++) {
if(!ipArray[i].ip.isEmpty()){
QString msg = "[" + QDateTime::currentDateTime().toString("MM/dd/yyyy hh:mm:ss") + "] ";
QTcpSocket * test = new QTcpSocket;
test->connectToHost(QHostAddress(ipArray[i].ip), ipArray[i].port);
if(test->waitForConnected(2000)) {
msg += ipArray[i].ip + ": Test Message Sent";
ui->testBrowser->append("<font color=green>" + msg + "</font>");
test->abort();
}
else {
msg += ipArray[i].ip + ": Failed to Connect";
ui->testBrowser->append("<font color=red>" + msg + "</font>");
}
}
}
if(!initial) {
QString fips = fipsNo.trimmed().remove("VAZ");
QString msgToSend = "A 100 " + QDateTime::currentDateTime().toString("MM/dd/yyyy hh:mm:ss") + " " + QString::number(boxGID);
sendBase(msgToSend, true);
sendRaw(msgToSend);
sendRawStrtoIflows(QString(encode(msgToSend)));
}
else initial = false;
}
示例3: recieveConnection
void Server::recieveConnection()
{
if (is_init_connection) return;
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
QString client_ip = clientConnection->peerAddress().toString();
quint32 client_ip_int = clientConnection->peerAddress().toIPv4Address();
emit write_message(tr("New connection from IP: %1").arg(client_ip));
connect(clientConnection, SIGNAL(disconnected()), clientConnection, SLOT(deleteLater()));
if (client_ip_int == QHostAddress(remoteIPAddress).toIPv4Address() || is_config_mode) {
if (remote_server_socket && clientConnection != remote_server_socket) {
delete remote_server_socket;
}
remote_server_socket = clientConnection;
connect(clientConnection, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
connect(clientConnection, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
connect(clientConnection, SIGNAL(readyRead()), this, SLOT(recieveData()));
connect(clientConnection, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));
} else {
clientConnection->abort();
}
}
示例4: streamLoop
void streamLoop(qintptr socketDesc, QQueue<QByteArray> &queue, bool& streaming) {
QTcpSocket* socket = new QTcpSocket();
// TCP_NODELAY + disable Nagle's algorithm
socket->setSocketOption(QAbstractSocket::LowDelayOption, QVariant::fromValue(1));
// Internetwork control
socket->setSocketOption(QAbstractSocket::TypeOfServiceOption, QVariant::fromValue(192));
socket->setSocketDescriptor(socketDesc);
socket->readAll();
QByteArray ContentType = ("HTTP/1.1 200 OK\r\n" \
"Server: test\r\n" \
"Cache-Control: no-cache\r\n" \
"Cache-Control: private\r\n" \
"Connection: close\r\n"\
"Pragma: no-cache\r\n"\
"Content-Type: multipart/x-mixed-replace; boundary=--boundary\r\n\r\n");
socket->write(ContentType);
while((socket->state() != QAbstractSocket::ClosingState ||
socket->state() != QAbstractSocket::UnconnectedState) &&
socket->state() == QAbstractSocket::ConnectedState &&
streaming) {
if(queue.empty()) { // no new frame available
continue;
}
// make sure that the queue doesn't grow too big or
// the OOM killer will kick in
if(queue.length() > 20) {
queue.clear();
continue;
}
QByteArray boundary = ("--boundary\r\n" \
"Content-Type: image/jpeg\r\n" \
"Content-Length: ");
QByteArray img = queue.dequeue();
boundary.append(QString::number(img.length()));
boundary.append("\r\n\r\n");
socket->write(boundary);
socket->waitForBytesWritten();
boundary.clear();
socket->write(img);
socket->waitForBytesWritten();
img.clear();
}
socket->flush();
socket->abort();
socket->deleteLater();
streaming = false;
queue.clear();
return;
}
示例5: detectCupsService
bool FilePrinter::detectCupsService()
{
QTcpSocket qsock;
qsock.connectToHost("localhost", 631);
bool rtn = qsock.waitForConnected() && qsock.isValid();
qsock.abort();
return rtn;
}
示例6: tcp_ping
//.........这里部分代码省略.........
// Header: channel (1)
byteArray.append(randValues.at(i++));
// Header: UUID (16)
QUuid uuid;
uuid = QUuid::createUuid();
QByteArray uuid_arr = uuid.toRfc4122();
for(int j=0; j<16;j++) {
byteArray.append(uuid_arr.at(j));
}
// Header: Empty IP address (4) and port number (2)
byteArray.append(QByteArray(6, '\0'));
// Header: time (8)
byteArray.append(QByteArray(8, '\0'));
// Header: type (1)
byteArray.append(randValues.at(i++));
// Header: size (1) and data
rand = randValues.at(i++);
byteArray.append(rand);
byteArray.append(QByteArray(rand, rand));
// Contextinformation: type (1)
byteArray.append(randValues.at(i++));
// Contextinformation: root-CIC (2)
byteArray.append(randValues.at(i++));
byteArray.append(randValues.at(i++));
// Contextinformation: size (1)
rand = randValues.at(i++);
byteArray.append(rand);
byteArray.append(QByteArray(rand*2, rand));
// Application: type (1)
byteArray.append(randValues.at(i++));
// Application: size (1)
rand = randValues.at(i++);
byteArray.append(rand);
byteArray.append(QByteArray(rand, rand));
} // rand
/**
* Sent via TCP
*/
QTcpSocket *tcpSocket;
tcpSocket = new QTcpSocket();
QTextStream outStream(stdout);
QString out;
tcpSocket->abort();
tcpSocket->connectToHost("127.0.0.1", 22365);
qDebug() << "waitForConnected!";
if (tcpSocket->waitForConnected(5000)) {
qDebug() << "Connected!";
}
else {
errorStream << "Error: tcp_ping(" << command.join(" ") << ") No connection available!" << endl;
return 1;
}
out = QString("BytesWritten: %1").arg(tcpSocket->write(byteArray, byteArray.length()));
qDebug() << out;
int numRead = 0, numReadTotal = 0;
char buffer[MAXMSG];
forever {
numRead = tcpSocket->read(buffer, MAXMSG);
qDebug() << "read buffer";
qDebug() << buffer;
numReadTotal += numRead;
if (numRead == 0 && !tcpSocket->waitForReadyRead())
break;
}
qDebug() << numReadTotal << " bytes red";
tcpSocket->flush();
tcpSocket->disconnectFromHost();
tcpSocket->close();
outStream << out << endl;
return 0;
}
示例7: SendData
bool Server::SendData(QHostAddress ip_to, QString message)
{
bool result = false;
QTcpSocket* tcpSocket = sockets->value(ip_to.toIPv4Address(), 0);
if (tcpSocket && tcpSocket->state()==QAbstractSocket::ConnectedState && tcpSocket->isWritable()) {
emit write_message(tr("Sending data (size=%1) to %2. Content: \"%3\"").arg(message.length()).arg(ip_to.toString()).arg(message));
tcpSocket->write(message.toUtf8());
result = tcpSocket->waitForBytesWritten();
} else {
tcpSocket = new QTcpSocket();
tcpSocket->connectToHost(ip_to, remote_port, QIODevice::ReadWrite);
tcpSocket->waitForConnected(5000);
if (tcpSocket->state()==QAbstractSocket::ConnectedState) {
emit write_message(tr("Sending data (size=%1) from new socket to %2. Content: \"%3\"").arg(message.length()).arg(ip_to.toString()).arg(message));
tcpSocket->write(message.toUtf8());
result = tcpSocket->waitForBytesWritten(5000);
} else {
emit error(tr("Client \"%1\" not found").arg(ip_to.toString()));
}
tcpSocket->abort();
delete tcpSocket;
}
return result;
}
示例8: setSocket
void ProtocolSocket::setSocket(QTcpSocket *socket)
{
if (socket && socket->state() != QAbstractSocket::ConnectedState) {
qWarning() << "BUG: ProtocolSocket::setSocket with unconnected socket";
socket = 0;
}
if (socket == m_socket)
return;
bool wasConnected = isConnected();
if (m_socket) {
/* The existing socket is replaced, and all pending commands
* are considered failed. This could be improved on. */
QTcpSocket *oldSocket = m_socket;
m_socket = 0;
oldSocket->disconnect(this);
// XXX can this be avoided if none are sent yet?
abortCommands();
oldSocket->abort();
oldSocket->deleteLater();
}
m_socket = socket;
if (socket) {
socket->setParent(this);
connect(socket, SIGNAL(readyRead()), this, SLOT(read()));
// QueuedConnection used to make sure socket states are updated first
connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected()),
Qt::QueuedConnection);
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(socketDisconnected()), Qt::QueuedConnection);
if (!wasConnected) {
m_connectedTime.restart();
emit connected();
}
flushCommands();
read();
} else {
emit disconnected();
}
emit socketChanged();
}