-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclientexec.cpp
More file actions
53 lines (43 loc) · 1.6 KB
/
Copy pathclientexec.cpp
File metadata and controls
53 lines (43 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "clientexec.h"
extern const std::string version;
// restructure !!!
int remoteStop(QString serverName, const int &serverPort)
{
// init
int output = 1;
QTcpSocket tcpSocket;
QString domainName = QHostInfo::localDomainName();
// check server name - if empty, use local host
serverName = (serverName.isEmpty())?QHostAddress(QHostAddress::LocalHost).toString():serverName;
//---------------------
// connect to server
//--------------------- not IP address AND name doesn't contain domain name
tcpSocket.connectToHost(serverName+((QHostAddress(serverName).isNull() && !serverName.contains(domainName))?"."+domainName:""),serverPort);
// wait for connection
if (tcpSocket.waitForConnected())
{
//---------------------
// create data stream -> to function
//---------------------
Buffer *buffer = createBuffer(Kill,0);
// to function OR wrapper class
TSize size;
TPointer *data = bufferToStreamData(buffer,&size);
clearBuffer(buffer);
//---------------------
// send data
//---------------------
tcpSocket.write((char*)data,size);
// wait for written
if (tcpSocket.waitForBytesWritten())
output = 0;
//---------------------
// disconnect
//---------------------
tcpSocket.disconnectFromHost();
if (tcpSocket.state() != QAbstractSocket::UnconnectedState)
tcpSocket.waitForDisconnected();
}
// return
return output;
}