-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyserver.cpp
56 lines (38 loc) · 1.35 KB
/
myserver.cpp
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
54
//This is server code that listens at port 1234//
#include "myserver.h"
#include "thread.h"
MyServer::MyServer(QObject *parent) : QTcpServer(parent)
{
}
void MyServer::StartServer()
{
// Change: 1234 to your required port
if(!this->listen(QHostAddress::Any,1234))
{
emit statusinf("Server could not be started. Please relaunch the app.");
}
else {
emit statusinf("Listening on port 1234.");
}
}
void MyServer::info(QString str)
{
emit sendinf(str);
}
//Thread is created on incomming connection//
void MyServer::incomingConnection(qintptr socketDescriptor)
{
//Step 1: Create a new thread pointer and send the socket descriptor to it
//Step 2:
//connect 1: for deleting later
//connect 2: for sending info
//connect 3: for sending status info and updating it , connected etc
//connect 4: for sending the updated configuration file
//Step 3 : start the thread
Thread *thread = new Thread(socketDescriptor,this);
connect(thread,SIGNAL(finished()), thread, SLOT(deleteLater()));
connect(thread,&Thread::info, this, &MyServer::info);
connect(thread,&Thread::status, this, &MyServer::statusinf);
connect(this,&MyServer::sockwritesign,thread, &Thread::writeconfig);
thread->start();
}