Tianchi  v0.0.2 build 20130701
C++ library for Qt with VC & mingW
tcudp.h
1 // **************************************************************************
2 // Tianchi C++ library for Qt (open source)
3 // 天池共享源码库
4 // 版权所有 (C) 天池共享源码库开发组
5 // 授权协议:请阅读天池共享源码库附带的授权协议
6 // **************************************************************************
7 // 文档说明:UDP 协议的通讯器
8 // ==========================================================================
9 // 开发日志:
10 // 日期 人员 说明
11 // --------------------------------------------------------------------------
12 // 2013.05.03 圣域天子 建立
13 //
14 // ==========================================================================
16 // ==========================================================================
18 
19 #ifndef TIANCHI_TCUDP_H
20 #define TIANCHI_TCUDP_H
21 
22 #include <tianchi/tcglobal.h>
23 
24 #include <QtNetwork>
25 
26 class TIANCHI_API TcUdp : public QUdpSocket
27 {
28  Q_OBJECT
29  typedef QUdpSocket inherited;
30 public:
31  TcUdp();
32  virtual ~TcUdp();
33 
34  int start(int Port);
35  void stop();
36 
38  bool sendMessage(QHostAddress host, int port, QByteArray S);
40  inline bool sendMessage(QHostAddress host, int port, QString S)
41  { return sendMessage(host, port, S.toUtf8()); }
43  void sendBroadcast(int port, QByteArray S);
45  inline void sendBroadcast(int port, QString S)
46  { return sendBroadcast(port, S.toUtf8()); }
47 
49  inline void setRecvMethod(QObject* recvObject, QByteArray recvMethod)
50  { m_recvObject = recvObject; m_recvMethod = recvMethod; }
51 
52 Q_SIGNALS:
54  void recvMessage(QHostAddress client, QByteArray datagram);
55 
56 protected slots:
57  void udpRecv();
58 
59 protected:
60  QObject* m_recvObject;
61  QByteArray m_recvMethod;
62 };
63 
64 #endif // TIANCHI_TCUDP_H