1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef GRAPHIC_LITE_TCP_SOCKET_H
17 #define GRAPHIC_LITE_TCP_SOCKET_H
18 
19 #include <QtCore/qobject.h>
20 #include <QTcpServer>
21 #include <QTcpSocket>
22 #include <QHostAddress>
23 
24 #include "tcp_socket_manager.h"
25 
26 const QString IP = "127.0.0.1";
27 const quint16 port = 23495;
28 
29 namespace OHOS {
30 class TcpSocketClientManager;
31 class TcpScoketClient : public QObject {
32     Q_OBJECT
33 
34 public:
35     TcpScoketClient();
36     virtual ~TcpScoketClient();
37     void CreateTCPScoket();
38     void SetScoketManager(TcpSocketClientManager* tcpSocketManager);
39     void OnSendMessage(QString& message);
40     void ConnectSocket();
41 
42 private slots:
43     void OnConnected();
44     void OnDisconnected();
45     void OnSocketStateChange(QAbstractSocket::SocketState socketState);
46     void OnSocketReadyRead();
47 
48 public:
49 
50 private:
51     QTcpSocket* tcpSocket_;
52     TcpSocketClientManager* tcpSocketManager_;
53 };
54 } // namespace OHOS
55 
56 #endif // GRAPHIC_LITE_TCP_SOCKET_H
57