-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmytcpserver.cpp
39 lines (31 loc) · 853 Bytes
/
mytcpserver.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
/**************************************************
* Copyright (C) 2021 ARAD. All Rights Reserved. *
***************************************************/
#ifndef MYTCPSERVER_H
#define MYTCPSERVER_H
#include "mytcpserver.h"
mytcpserver::MyTcpServer(QObject * parent):
QObject(parent)
{
server = new QTcpServer(this);
// whenever a user connects, it will emit signal
connect(server, SIGNAL(newConnection()),
this, SLOT(newConnection()));
if (!server->listen(QHostAddress::Any, 9999))
{
qDebug() << "Server could not start";
}
else
{
qDebug() << "Server started!";
}
}
void mytcpserver::newConnection()
{
// need to grab the socket
QTcpSocket *socket = server->nextPendingConnection();
socket->write("Hello client\r\n");
socket->flush();
socket->waitForBytesWritten(3000);
socket->close();
}