本文整理汇总了C++中connectToHost函数的典型用法代码示例。如果您正苦于以下问题:C++ connectToHost函数的具体用法?C++ connectToHost怎么用?C++ connectToHost使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connectToHost函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: commandStarted
Network::Network(const QString &host, quint16 port) : commandStarted(false)
{
if (port == 0) {
//Default argument, not worth going further
} else {
connectToHost(host, port);
}
connect(this, SIGNAL(readyRead()), SLOT(onReceipt()));
}
开发者ID:Airisu,项目名称:pokemon-online,代码行数:10,代码来源:network.cpp
示例2: connectToHost
void OftSocket::directConnect(const QHostAddress &addr, quint16 port)
{
m_state = ReadHeader;
connectToHost(addr, port);
m_clientPort = port;
m_timer.start();
debug().nospace() << "Trying to establish a direct connection to "
<< addr.toString().toLocal8Bit().constData()
<< ":" << port;
}
开发者ID:AlexeyProkhin,项目名称:ireen,代码行数:10,代码来源:oscarfiletransfer.cpp
示例3: connectToHost
void ZMClient::restartConnection()
{
// Reset the flag
m_zmclientReady = false;
m_bConnected = false;
m_server_unavailable = false;
// Retry to connect. . . Maybe the user restarted mythzmserver?
connectToHost(m_hostname, m_port);
}
开发者ID:ReArtu,项目名称:mythtv,代码行数:10,代码来源:zmclient.cpp
示例4: QMainWindow
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->gameBox->setEnabled(FALSE);
connect(ui->clientButton, SIGNAL(released()), this, SLOT(connectToHost()));
connect(ui->serverButton, SIGNAL(released()), this, SLOT(runServer()));
moves = 0;
}
开发者ID:safiyat,项目名称:TicTacToe,代码行数:10,代码来源:MainWindow.cpp
示例5: connectToHost
void ApcUpsMon::requestEvents()
{
if (socket.state() == QAbstractSocket::ConnectedState) {
socket.putChar('\0');
socket.putChar('\x06');
socket.write("events");
} else {
// We're not connected, try and reconnect?
connectToHost();
}
}
开发者ID:licehunter,项目名称:plasma-apcups,代码行数:11,代码来源:apcupsc.cpp
示例6: Q_ASSERT
void Connection::connectToServer() {
Q_ASSERT(!m_host.isEmpty());
Q_ASSERT(m_port);
connect(this, SIGNAL(connected()), SLOT(onConnected()), Qt::UniqueConnection);
connect(this, SIGNAL(disconnected()), SLOT(onDisconnected()), Qt::UniqueConnection);
connect(this, SIGNAL(readyRead()), SLOT(onReadyRead()), Qt::UniqueConnection);
connect(this, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(onError(QAbstractSocket::SocketError)), Qt::UniqueConnection);
connectToHost(m_host, m_port);
}
开发者ID:Anvar69,项目名称:libqtelegram-aseman-edition,代码行数:11,代码来源:connection.cpp
示例7: while
void *connect(void *data){
struct program_data *tData;
tData = (struct program_data*) data;
while ((*tData).hasQuit == 0){
connectToHost((*tData).ipInput);
sleep(10);//prevents spamming the network if server is down
}
return NULL;
}
开发者ID:dewso,项目名称:ReStat,代码行数:11,代码来源:main.cpp
示例8: QObject
Server::Server(QObject * parent) : QObject(parent)
{
_server = new QTcpServer(this);
connect(_server, SIGNAL(newConnection()), SLOT(connected()));
if(connectToHost(QHostAddress::Any, 8081)) {
// Pokud jsme tady, server jeste neni pripojen k Log!!!
syslog(LOG_INFO, "Server is listening...");
} else {
syslog(LOG_ERR, "Could not listen on given port!");
}
}
开发者ID:puzzleSEQ,项目名称:server,代码行数:11,代码来源:server.cpp
示例9: Q_D
/*!
If there's a connection activity on the socket, process it. Then
notify our parent if there really was activity.
*/
void QNativeSocketEngine::connectionNotification()
{
Q_D(QNativeSocketEngine);
Q_ASSERT(state() == QAbstractSocket::ConnectingState);
connectToHost(d->peerAddress, d->peerPort);
if (state() != QAbstractSocket::ConnectingState) {
// we changed states
QAbstractSocketEngine::connectionNotification();
}
}
开发者ID:Blizzard,项目名称:qt4,代码行数:15,代码来源:qnativesocketengine.cpp
示例10: QMainWindow
MainWindow::MainWindow(Socket *connection, QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
connection(connection)
{
ui->setupUi(this);
/* Disable unavailable offline control
*/
ui->configurationWidget->setDisabled(true);
ui->controlWidget->setDisabled(true);
ui->PiecesDock->setDisabled(true);
ui->stopButton->setDisabled(true);
ui->resumeButton->setDisabled(true);
/* Connection/Disconnection notification
*/
connect(connection, SIGNAL(connected()), this, SLOT(connectionNotify()));
connect(connection, SIGNAL(disconnected()), this, SLOT(disconnectionNotify()));
/* Received logLine
*/
connect(connection, SIGNAL(gotLog(QString)), this, SLOT(appendLog(QString)));
/* Received Boxed info
*/
connect(connection, SIGNAL(gotAccepted(int)), this, SLOT(addAccepted(int)));
connect(connection, SIGNAL(gotRejected(int)), this, SLOT(addRejected(int)));
/* Received Error / Warning
*/
connect(connection, SIGNAL(gotError(int)), this, SLOT(errorNotify(int)));
//connect(connection, SIGNAL(gotWarning(int)), this, SLOT(warningNotify(int)));
/* Connection button
*/
connect(ui->ConnectionButton, SIGNAL(clicked()), this, SLOT(connectToHost()));
/* Send configuration data button
*/
connect(ui->sendConfigButton, SIGNAL(clicked()), this, SLOT(sendConfig()));
/* Actions button : Lauch / Resume / Stop
*/
connect(ui->launchButton, SIGNAL(clicked()), this, SLOT(launch()));
connect(ui->resumeButton, SIGNAL(clicked()), this, SLOT(resume()));
connect(ui->stopButton, SIGNAL(clicked()), this, SLOT(stop()));
/* Refresh time display
*/
connect(&timer, SIGNAL(timeout()), this, SLOT(displayTime()));
timer.start(50);
}
开发者ID:modSquad,项目名称:cmmai,代码行数:54,代码来源:mainwindow.cpp
示例11: SLOT
// Have a socket error, set m_errorString and propagate
// signal
void ApcUpsMon::socketError(QAbstractSocket::SocketError)
{
m_errorString = socket.errorString();
if (socket.state() != QAbstractSocket::ConnectedState) {
// Attempt to reconnect in two timer intervals or,
// failing that, ten seconds
QTimer::singleShot((timer.interval() ? timer.interval() : 10000),
this, SLOT(connectToHost()));
}
emit haveError(m_errorString);
}
开发者ID:licehunter,项目名称:plasma-apcups,代码行数:14,代码来源:apcupsc.cpp
示例12: waitForWrite
/*!
Waits for \a msecs milliseconds or until the socket is ready for
writing. If \a timedOut is not 0 and \a msecs milliseconds have
passed, the value of \a timedOut is set to true.
Returns true if data is available for writing; otherwise returns
false.
This is a blocking function call; its use is disadvised in a
single threaded application, as the whole thread will stop
responding until the function returns. waitForWrite() is most
useful when there is no event loop available. The general approach
is to create a QSocketNotifier, passing the socket descriptor
returned by socketDescriptor() to its constructor.
*/
bool QNativeSocketEngine::waitForWrite(int msecs, bool *timedOut)
{
Q_D(QNativeSocketEngine);
Q_CHECK_VALID_SOCKETLAYER(QNativeSocketEngine::waitForWrite(), false);
Q_CHECK_NOT_STATE(QNativeSocketEngine::waitForWrite(),
QAbstractSocket::UnconnectedState, false);
if (timedOut)
*timedOut = false;
int ret = d->nativeSelect(msecs, false);
// On Windows, the socket is in connected state if a call to
// select(writable) is successful. In this case we should not
// issue a second call to WSAConnect()
#if defined (Q_WS_WIN)
if (ret > 0) {
setState(QAbstractSocket::ConnectedState);
d_func()->fetchConnectionParameters();
return true;
} else {
int value = 0;
int valueSize = sizeof(value);
if (::getsockopt(d->socketDescriptor, SOL_SOCKET, SO_ERROR, (char *) &value, &valueSize) == 0) {
if (value == WSAECONNREFUSED) {
d->setError(QAbstractSocket::ConnectionRefusedError, QNativeSocketEnginePrivate::ConnectionRefusedErrorString);
d->socketState = QAbstractSocket::UnconnectedState;
return false;
} else if (value == WSAETIMEDOUT) {
d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::ConnectionTimeOutErrorString);
d->socketState = QAbstractSocket::UnconnectedState;
return false;
} else if (value == WSAEHOSTUNREACH) {
d->setError(QAbstractSocket::NetworkError, QNativeSocketEnginePrivate::HostUnreachableErrorString);
d->socketState = QAbstractSocket::UnconnectedState;
return false;
}
}
}
#endif
if (ret == 0) {
if (timedOut)
*timedOut = true;
d->setError(QAbstractSocket::SocketTimeoutError,
QNativeSocketEnginePrivate::TimeOutErrorString);
d->hasSetSocketError = false; // A timeout error is temporary in waitFor functions
return false;
} else if (state() == QAbstractSocket::ConnectingState) {
connectToHost(d->peerAddress, d->peerPort);
}
return ret > 0;
}
开发者ID:Blizzard,项目名称:qt4,代码行数:68,代码来源:qnativesocketengine.cpp
示例13: login
bool KMSmtpClient::login()
{
//Check out state.
if((!isConnected()) && (!connectToHost()))
{
//Means socket is still not connected to server or already login.
return false;
}
//Check auth method.
if(authMethod()==AuthPlain)
{
//Sending command: AUTH PLAIN base64('\0' + username + '\0' + password)
sendMessage("AUTH PLAIN " + QByteArray().append((char)0x00)
.append(userName()).append((char)0x00)
.append(password()).toBase64());
// The response code needs to be 235.
if(!waitAndCheckResponse(235, ServerError))
{
//Failed to login.
return false;
}
//Mission complete.
return true;
}
//Then the method should be auth login.
// Sending command: AUTH LOGIN
sendMessage("AUTH LOGIN");
//The response code needs to be 334.
if(!waitAndCheckResponse(334, AuthenticationFailedError))
{
//Failed to login.
return false;
}
// Send the username in base64
sendMessage(QByteArray().append(userName()).toBase64());
//The response code needs to be 334.
if(!waitAndCheckResponse(334, AuthenticationFailedError))
{
//Failed to login.
return false;
}
// Send the password in base64
sendMessage(QByteArray().append(password()).toBase64());
//If the response is not 235 then the authentication was faild
if(!waitAndCheckResponse(235, AuthenticationFailedError))
{
//Failed to login.
return false;
}
//Mission compelte.
return true;
}
开发者ID:Kreogist,项目名称:Mail,代码行数:52,代码来源:kmsmtpclient.cpp
示例14: enviarRespuesta
void enviarRespuesta(char* hostname,char* respuesta) {
char request[1000];
setupSocket(hostname);
connectToHost(hostname);
sprintf(request,"GET /index.php?r=juego/respuesta&tokenSolicitud=%s&solucion=%s HTTP/1.1\r\nHost: %s\r\n\r\n",tokenSolicitud,respuesta,hostname);
//http://hornero.fi.uncoma.edu.ar/index.php?r=juego/respuesta&&tokenSolicitud=76d7cadd3df99e06ae8c4aa580ca6900&solucion=-5933
printf("\nse envia request: %s\n", request);
if (send(sock, request, sizeof(request), 0) != (int)sizeof(request)) {
printf( "Error sending request." );
exit(1);
}
getBuffer();
}
开发者ID:cnngimenez,项目名称:hornero,代码行数:13,代码来源:hornero.c
示例15: setServerPort
void TcpClient::tryConnectToHost(const QString &host, int port)
{
setServerPort(port);
if (host == zeroHost) {
if (!findLocalIpv4InterfaceData()) {
return;
}
} else {
if (connectToHost(host, port)) {
setServerIp(host);
}
}
}
开发者ID:TatianaBorisova,项目名称:TestApplication,代码行数:13,代码来源:tcpclient.cpp
示例16: enviarSolicitud
void enviarSolicitud(char* hostname, char* token,char* problema) {
char request[1000];
setupSocket(hostname);
connectToHost(hostname);
sprintf(request,"GET /index.php?r=juego/solicitud&token=%s&problema=%s HTTP/1.1\r\nHost: %s\r\n\r\n",token,problema,hostname);
//printf("se envia request: %s", request);
if (send(sock, request, sizeof(request), 0) != (int)sizeof(request)) {
printf( "Error sending request." );
exit(1);
}
getBuffer();
}
开发者ID:cnngimenez,项目名称:hornero,代码行数:13,代码来源:hornero.c
示例17: addToLog
bool ftpInterface::uploadFile(QString fileName,QString fixFilename,bool deleteSource)
{
delSrc=deleteSource;
// progress->show();
aborting=FALSE;
addToLog("FTP uploadFile",LOGFTP);
if ( fileName.isNull() ) return FALSE;
ftpDone=TRUE;
if(isUnconnected())
{
ftpDone=FALSE;
connectToHost();
}
while(!ftpDone)
{
if(aborting) return FALSE;
qApp->processEvents();
}
sourceFn=new QFile(fileName);
if ( !sourceFn->open( QIODevice::ReadOnly ) )
{
// QMessageBox::critical( 0, tr("Upload error"),
// tr("Can't open file '%1' for reading.").arg(fileName) );
delete sourceFn;
sourceFn=NULL;
return FALSE;
}
QFileInfo fi( fileName );
QFileInfo fin(fixFilename);
addToLog(QString("FTP bytes: %1").arg(sourceFn->size()),LOGFTP);
ftpDone=FALSE;
int id=ftp->put( sourceFn, fi.fileName(),QFtp::Binary);
addToLog(QString("FTP put file id: %1").arg(id),LOGFTP);
while(!ftpDone)
{
if(aborting) return FALSE;
qApp->processEvents();
}
if(!fixFilename.isEmpty())
{
ftp->rename(fi.fileName(),fin.fileName());
}
addToLog("FTP starting progress",LOGFTP);
//progress->exec(); // ### takes a lot of time!!!
return TRUE;
}
开发者ID:castrouk,项目名称:LinDrm,代码行数:49,代码来源:ftp.cpp
示例18: BenchmarkClient
void Benchmark::connectToHost()
{
if (m_count < m_usersCount) {
BenchmarkClient *client;
if (m_authIn.size() > m_count)
client = new BenchmarkClient(m_authIn.at(m_count).toMap(), this);
else
client = new BenchmarkClient(m_nickPrefix + QString::number(m_count), this);
connect(client->io(), SIGNAL(clientStateChanged(int,int)), SLOT(clientStateChanged(int,int)));
client->open(m_serverAddr);
// client->setNick(m_nickPrefix + QString::number(m_count));
// client->setCookieAuth(false);
// client->openUrl(m_serverAddr);
// QSettings settings(m_chatConf, QSettings::IniFormat, this);
// settings.setIniCodec("UTF-8");
// settings.setValue("Profile/Nick", m_nickPrefix + QString::number(m_count));
//
// QProcess *chat = new QProcess(this);
// m_process.append(chat);
//
// chat->start(m_chatFile);
// chat->waitForStarted();
// AbstractProfile *profile = new AbstractProfile();
// profile->setNick(m_nickPrefix + QString::number(m_count));
// connect(this, SIGNAL(finished()), profile, SLOT(deleteLater()));
// ClientService *service = new ClientService(profile, m_network);
// connect(this, SIGNAL(finished()), service, SLOT(deleteLater()));
#if !defined(BENCHMARK_NO_UI)
// connect(service, SIGNAL(accessGranted(QString,QString,quint16)), SLOT(accessGranted(QString,QString,quint16)));
// connect(service, SIGNAL(accessDenied(quint16)), SLOT(accessDenied(quint16)));
// connect(service, SIGNAL(syncUsersEnd()), SLOT(syncUsersEnd()));
// connect(service, SIGNAL(unconnected(bool)), SLOT(unconnected()));
emit started(++m_count);
#else
++m_count;
#endif
// msleep(m_connectInterval);
// connectToHost();
// service->connectToHost();
QTimer::singleShot(m_connectInterval, this, SLOT(connectToHost()));
}
开发者ID:johnbolia,项目名称:schat,代码行数:49,代码来源:benchmark.cpp
示例19: connectToHost
bool CTcpClient::Connect2Server( const QHostAddress &hostAddr, quint16 nPort )
{
svrAddr = hostAddr;
nSvrPort = nPort;
try {
connectToHost( svrAddr, nSvrPort );
} catch ( ... ) {
int n = 0;
n++;
return false;
}
return true;
}
开发者ID:Anne081031,项目名称:ParkCode,代码行数:15,代码来源:tcpclient.cpp
示例20: connectToHost
Response Client::get(const string &path)
{
connectToHost();
std::ostringstream request_stream;
request_stream << "GET " << path << " HTTP/1.1\r\n";
request_stream << "Host: " << host_.hostName() << "\r\n";
request_stream << "Accept: */* \r\n";
if (x_api_key_ != "")
request_stream << "X-Api-Key: " << x_api_key_ << "\r\n";
if (access_token_ != "")
request_stream << "Authorization: Bearer " << access_token_ << "\r\n";
request_stream << "Connection: close \r\n\r\n"; // close socket connection after get all response
return getResponse(request_stream.str());
}
开发者ID:nguyendv,项目名称:httpclient,代码行数:15,代码来源:client.cpp
注:本文中的connectToHost函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论