Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "server.h"
- Server::Server(QObject *parent, uint port_wej) : QObject(parent)
- {
- if (!Serwer){
- Serwer = new QTcpServer(this);
- connect (Serwer, SIGNAL(newConnection()),this,SLOT(newConnection()));
- }
- if(Serwer->isListening()==false)
- {
- Serwer->listen((QHostAddress::Any), port_wej);
- }
- }
- void Server::newConnection()
- {
- if (Serwer->hasPendingConnections()==true)
- {
- socket = Serwer->nextPendingConnection();
- connect (socket, SIGNAL(connected()),this, SLOT(SocketConnected()));
- connect (socket, SIGNAL(disconnected()),this,SLOT(SocketDisconnected()));
- socket->write("Something\r\n");
- socket->flush();
- socket->waitForBytesWritten(3000);
- socket->close();
- Serwer->close();
- // socket->pauseMode();
- }
- }
- void Server::SocketConnected()
- {
- QString label_connected = "<html><head/><body><p><span style=\" font-weight:600;\">Connected</span> with IP 127.0.0.1</p></body></html>";
- emit Connected(label_connected);
- }
- void Server::SocketDisconnected()
- {
- QString label_disconnected = "<html><head/><body><p><span style=\" font-weight:600;\">Disconnected</span> with IP 127.0.0.1</p></body></html>";
- emit Disconnected(label_disconnected);
- }
- void Server::Disconnect()
- {
- Serwer->close();
- socket->close();
- socket->~QTcpSocket();
- Serwer->~QTcpServer();
- }
- uint Server::GetStatus()
- {
- return status;
- }
Advertisement
Add Comment
Please, Sign In to add comment