本文整理汇总了C++中QTcpSocket::close方法的典型用法代码示例。如果您正苦于以下问题:C++ QTcpSocket::close方法的具体用法?C++ QTcpSocket::close怎么用?C++ QTcpSocket::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTcpSocket
的用法示例。
在下文中一共展示了QTcpSocket::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slotReadClient
void ourtrackserv::slotReadClient()
{
QTcpSocket* clientSocket = (QTcpSocket*)sender();
int idusersocs = clientSocket->socketDescriptor();
// Получаем флаг запроса
char flag;
if (!clientSocket->getChar(&flag))
{
qDebug() << "Error flag read";
clientSocket->close();
SClients.remove(idusersocs);
return;
}
switch (flag)
{
case FLAG_FIND:
{
FindQueryDissect(clientSocket);
break;
}
case FLAG_ADD:
{
AddQueryDissect(clientSocket);
break;
}
case FLAG_LIKED:
{
LikeQueryDissect(clientSocket);
break;
}
case FLAG_LAST:
{
GetLastQueryDissect(clientSocket);
break;
}
case FLAG_PLDOWN:
{
PlusDownloadQueryDissect(clientSocket);
break;
}
default:
{
break;
}
}
clientSocket->close();
SClients.remove(idusersocs);
}
示例2: readClient
void HttpDaemon::readClient()
{
if (disabled)
return;
// This slot is called when the client sent data to the server. The
// server looks if it was a get request and sends a very simple HTML
// document back.
QTcpSocket* socket = (QTcpSocket*)sender();
if (socket->canReadLine()) {
QByteArray data = socket->readLine();
QStringList tokens = QString(data).split(QRegExp("[ \r\n][ \r\n]*"));
qDebug() << "incoming data" << tokens[1];
QUrl url("http://foo.bar" + tokens[1]);
QUrlQuery query(url);
qDebug() << "query is" << url.path();
if (url.path() == "/setstate") {
emit setState(StateTypeId(query.queryItems().first().first), QVariant(query.queryItems().first().second));
} else if (url.path() == "/generateevent") {
qDebug() << "got generateevent" << query.queryItemValue("eventtypeid");
emit triggerEvent(EventTypeId(query.queryItemValue("eventtypeid")));
} else if (url.path() == "/actionhistory") {
QTextStream os(socket);
os.setAutoDetectUnicode(true);
os << generateHeader();
for (int i = 0; i < m_actionList.count(); ++i) {
os << m_actionList.at(i).first.toString() << '\n';
}
socket->close();
return;
} else if (url.path() == "/clearactionhistory") {
m_actionList.clear();
}
if (tokens[0] == "GET") {
QTextStream os(socket);
os.setAutoDetectUnicode(true);
os << generateWebPage();
socket->close();
qDebug() << "Wrote to client";
if (socket->state() == QTcpSocket::UnconnectedState) {
delete socket;
qDebug() << "Connection closed";
}
}
}
}
示例3: handleNewConnection
void HttpSocket::handleNewConnection()
{
DBUG;
while (hasPendingConnections()) {
QTcpSocket *socket = nextPendingConnection();
// prevent clients from sending too much data
socket->setReadBufferSize(constMaxBuffer);
static const QLatin1String constIpV6Prefix("::ffff:");
QString peer=socket->peerAddress().toString();
QString ifaceAddress=serverAddress().toString();
const bool hostOk=peer==ifaceAddress || peer==mpdAddr || peer==(constIpV6Prefix+mpdAddr) ||
peer==QLatin1String("127.0.0.1") || peer==(constIpV6Prefix+QLatin1String("127.0.0.1"));
DBUG << "peer:" << peer << "mpd:" << mpdAddr << "iface:" << ifaceAddress << "ok:" << hostOk;
if (!hostOk) {
sendErrorResponse(socket, 400);
socket->close();
DBUG << "Not from valid host";
return;
}
connect(socket, SIGNAL(readyRead()), this, SLOT(readClient()));
connect(socket, SIGNAL(disconnected()), this, SLOT(discardClient()));
}
}
示例4: os
void HttpServer :: readClient()
{
if (disabled) return;
QTcpSocket *socket = (QTcpSocket*)sender();
if( socket->canReadLine()) {
QString request = socket->readLine();
QStringList tokens = request.split(QRegExp("[ \r\n][ \r\n]*"));
if( tokens[0] == "GET") {
d->engine.globalObject().setProperty("token", tokens[1]);
QScriptValue reply = d->engine.evaluate("reply(token)");
QTextStream os(socket);
os.setAutoDetectUnicode(true);
os << reply.toString().toUtf8();
socket->close();
QtServiceBase::instance()->logMessage("Wrote index.html");
if(socket->state() == QTcpSocket::UnconnectedState) {
delete socket;
QtServiceBase::instance()->logMessage("Conncetion closed");
}
}
}
}
示例5: get_ap_list
void aplist::get_ap_list()
{
QDataStream in(&tcpSocket);
quint8 type;
quint8 request_type;
char ssid_buf[512] = {0};
in.setByteOrder(QDataStream::LittleEndian);
in>>type>>request_type>>n_ap;
if(type!=0x02)
{
tcpSocket.close();
//error();
}
else if(type==0x02)
{
in.setByteOrder(QDataStream::LittleEndian);
if(request_type==0x01)
{
for(int i=0;i<n_ap;i++)
{
in>>ap_li[i].ssid_len;
in.readRawData(ssid_buf, ap_li[i].ssid_len);
ssid_buf[ap_li[i].ssid_len] = '\0';
ap_li[i].ssid = QString(ssid_buf);
in>>ap_li[i].encrypt_type;
in.readRawData((char *)ap_li[i].bssid, sizeof(ap_li[i].bssid));
}
show_data();
}
}
示例6: run
void ThreadJoueurs::run()
{
QTcpSocket unSocket;
unSocket.setSocketDescriptor(m_socketDescriptor);
if(unSocket.waitForConnected(1000))
{
while(unSocket.ConnectedState) //.waitForReadyRead(1000))
{
baRXInfos=unSocket.read(unSocket.bytesAvailable());
if(baRXInfos.left(1) == "&") //code de connection des joueurs
{
unSocket.write(baTXInfos.append(cNoJ)); //assignation du numero
baTXInfos = TXInfosToJoueurs(m_tNouvellePartie,9); // trame de debut de partie (= NouvellePartie)
}
else
{
RXInfosFmJoueurs(baRXInfos); //recoit {'#', JnX, JnY}
baTXInfos = TXInfosToJoueurs(m_txInfos,9); //repond trame {code, balle X, balle Y, J1X, J1Y, J2X, J2Y, ScoreA, ScoreB}
} // code = '#' (normale), '$' (gagnant), '%' (Nouvelle Balle)
unSocket.write(baTXInfos);
unSocket.waitForBytesWritten(10);
}
}
unSocket.disconnectFromHost();
unSocket.close();
}
示例7: while
void DataBus::Server::newClientConnected()
{
while (m_tcpServer.hasPendingConnections())
{
// Initialize new DataBus Client
QTcpSocket *socket = m_tcpServer.nextPendingConnection();
Client *client = new Client(this);
if (client->initialize(socket) == false)
{
// Error, failed to initialize socsocketket
if (socket != 0)
{
socket->close();
socket->deleteLater();
socket = 0;
}
continue;
}
connect(client, SIGNAL(clientDisconnected(Client*)), this, SLOT(clientDisconnected(Client*)));
connect(client, SIGNAL(newPacketReceived(Client*)), this, SLOT(processReceivedPacket(Client*)));
// Add client to list
addClient(client);
}
}
示例8: OnClientData
void TcpServer::OnClientData()
{
QTcpSocket* connection = qobject_cast<QTcpSocket*>(sender());
quint64 bufferSize = 2048;
char buffer[bufferSize];
quint64 dataRead = 0;
dataRead = connection->read(buffer, bufferSize);
buffer[dataRead] = 0;
//qDebug() << "[WEB] Incoming data[" << dataRead << "]: " << buffer;
QString value;
//Check if it's a Flash policy request, only the first time
//if (this->justConnected == true) {
value = buffer;
if (value.contains("<policy-file-request/>")) {
connection->write(XML_CROSS_DOMAIN);
qDebug() << "[TcpServer::OnClientData] Sent xml cross domain file";
//this->justConnected = false;
return;
}
else if ( value.contains("HTTP") ) { //then its HTTP request
QString response;
//Check the data and create response
DataHandler(value, response);
HttpResponse httpHeader(response);
connection->write( httpHeader.GetHeader() );
connection->write( response.toUtf8().constData() );
connection->close();
}
//}
//Other requests that are not http requests or posts
// This may be deleted
//else {
else if (value == "CORE") {
XmlParser xml(buffer, dataRead);
int action = CEMI_ACTION_WRITE;
int groupAddr = 0;
xml.GetValue("cmd", value);
if (value == "write") action = CEMI_ACTION_WRITE;
else if (value == "read") action = CEMI_ACTION_READ;
xml.GetValue("groupAddr", value);
groupAddr = Common::GroupAddrToInt(value);
//qDebug() << "groupAddr: " << value;
xml.GetValue("value", value);
emit TcpServerData((int)action, groupAddr, value);
}
//}
//this->justConnected = false;
}
示例9: run
void mjpegThread::run()
{
QTcpSocket *socket = new QTcpSocket(this);
connect(socket, SIGNAL(connected()),this, SLOT(connected()));
connect(socket, SIGNAL(disconnected()),this, SLOT(disconnected()));
connect(socket, SIGNAL(readyRead()),this, SLOT(readyRead()));
QUrl url(cfg->get("src1/url"), QUrl::TolerantMode);
socket->connectToHost(url.host(), 80);
if(!socket->waitForConnected(5000))
{
qDebug() << "Error: " << socket->errorString();
}
while (fRun)
{
sleep(1);
}
socket->close();
}
示例10: get_fake_list
void fakeap::get_fake_list()
{
QDataStream in(&tcpSocket);
quint8 type;
quint8 request_type;
char ssid_buf[512] = {0};
in.setByteOrder(QDataStream::LittleEndian);
in>>type>>request_type>>n_fake;
n_fake = 1;
ui->fake_num->display(n_fake);
if(type!=0x02)
{
tcpSocket.close();
//error();
}
else if(type==0x02)
{
in.setByteOrder(QDataStream::LittleEndian);
if(request_type==0x02)
{
for(int i=0;i<n_fake;i++)
{
in>>fake_li[i].ssid_len;
in.readRawData(ssid_buf, fake_li[i].ssid_len);
ssid_buf[fake_li[i].ssid_len] = '\0';
fake_li[i].ssid = QString(ssid_buf);
in>>fake_li[i].encrypt_type;
in.readRawData((char *)fake_li[i].bssid, sizeof(fake_li[i].bssid));
}
show_data();
}
}
示例11: deal_next_request
void brain_stroke_server::deal_next_request(){
puts("deal next");
//get next request
deque_mutex.lock();
if(request_list.size() != 0){
puts("has next");
QTcpSocket * client = request_list.front();
request_list.pop_front();
deque_mutex.unlock();
//ignore closing socket
if(client->state() == QTcpSocket::UnconnectedState || client->state() == QTcpSocket::ClosingState){
client->close();
QLOG_DEBUG() << "close client" << client;
std::cout << "close client:" << client->peerAddress().toString().toStdString() << std::endl;
//search next from request_list
deal_next_request();
return;
}
tcp_deal * tcp_deal_thread = new tcp_deal();
tcp_deal_thread -> set_socket(client);
connect(tcp_deal_thread, SIGNAL(finished()), this, SLOT(deal_next_request()));
connect(tcp_deal_thread, SIGNAL(finished()), tcp_deal_thread, SLOT(deleteLater()));
tcp_deal_thread -> start();
return;
}
deque_mutex.unlock();
QMutexLocker calculate_flag_mutex_locker(&calculate_flag_mutex);
//no calculating now
calculate_flag = false;
return;
}
示例12: OnClientDisconnection
void XSocket::OnClientDisconnection()
{
qDebug() << "[XSocket::OnClientDisconnection] Disconnected.";
QTcpSocket* connection = qobject_cast<QTcpSocket*>(sender());
connection->close();
connection->deleteLater();
}
示例13: OnClientError
void XSocket::OnClientError(QAbstractSocket::SocketError)
{
QTcpSocket* connection = qobject_cast<QTcpSocket*>(sender());
qDebug() << "[XSocket::OnClientError] Client error: " << connection->errorString();
connection->close();
connection->deleteLater();
}
示例14: slotReadClient
void WakeServer::slotReadClient()
{
QTcpSocket* clientSocket = (QTcpSocket*)sender();
int idusersocs=clientSocket->socketDescriptor();
wproto->getpacket(clientSocket->readAll());
// QTextStream os(clientSocket);
// os.setAutoDetectUnicode(true);
// os << "HTTP/1.0 200 Ok\r\n"
// "Content-Type: text/html; charset=\"utf-8\"\r\n"
// "\r\n"
// "<h1>WakeServer</h1>\n"
// << QDateTime::currentDateTime().toString() << "\n";
// qDebug() << "ReadClient:"+clientSocket->readAll()+"\n\r";
// // Если нужно закрыть сокет
clientSocket->close();
SClients.remove(idusersocs);
// while(tcpSocket->canReadLine())
// {
// QByteArray ba = tcpSocket->readLine();
// if(strcmp(ba.constData(), "!exit\r\n") == 0)
// {
// tcpSocket->disconnectFromHost();
// break;
// } else {
// }
// qDebug() << ">> " << ba.constData();
// }
}
示例15: onConnect
void GameServer::onConnect()
{
qDebug() << "CONNECTED";
QTcpSocket* socket = _server->nextPendingConnection();
socket->waitForReadyRead();
qDebug() << socket->bytesAvailable();
const int MaxLength = 1024;
char buffer[MaxLength + 1];
qint64 byteCount = socket->read(buffer, MaxLength);
buffer[byteCount] = 0;
qDebug() << buffer;
const char* response =
"HTTP/1.1 200 OK\r\n"
"Connection: close\r\n"
"Content-Type: text/html; charset=UTF-8\r\n"
"\r\n"
"<html><head><title>XPG Server</title></head>"
"<body><p>Hello, World! Text is da bomb.</p></body>"
"</html>"
;
qDebug() << socket->write(response);
socket->waitForBytesWritten();
socket->close();
delete socket;
}