last changes
This commit is contained in:
27
AdServer/AdServer.pro
Normal file
27
AdServer/AdServer.pro
Normal file
@@ -0,0 +1,27 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2012-07-14T18:11:58
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui network
|
||||
|
||||
TARGET = AdServer
|
||||
TEMPLATE = app
|
||||
|
||||
|
||||
SOURCES += main.cpp\
|
||||
widget.cpp \
|
||||
server.cpp \
|
||||
connection.cpp \
|
||||
client.cpp \
|
||||
clientbase.cpp
|
||||
|
||||
HEADERS += widget.h \
|
||||
server.h \
|
||||
connection.h \
|
||||
client.h \
|
||||
clientbase.h \
|
||||
message.h
|
||||
|
||||
FORMS += widget.ui
|
||||
16
AdServer/client.cpp
Normal file
16
AdServer/client.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "client.h"
|
||||
|
||||
Client::Client(QObject *parent) :
|
||||
ClientBase(parent)
|
||||
{
|
||||
m_socket = new QTcpSocket();
|
||||
connect(m_socket,SIGNAL(readyRead()),this,SLOT(readData()));
|
||||
connect(m_socket,SIGNAL(disconnected()),this,SLOT(Disconnection()));
|
||||
}
|
||||
|
||||
|
||||
void Client::connectToServer(QHostAddress addr)
|
||||
{
|
||||
m_socket->connectToHost(addr,44461);
|
||||
}
|
||||
|
||||
25
AdServer/client.h
Normal file
25
AdServer/client.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef CLIENT_H
|
||||
#define CLIENT_H
|
||||
|
||||
#include <QObject>
|
||||
#include "clientbase.h"
|
||||
|
||||
|
||||
class Client : public ClientBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Client(QObject *parent = 0);
|
||||
void connectToServer(QHostAddress addr);
|
||||
|
||||
private:
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // CLIENT_H
|
||||
66
AdServer/clientbase.cpp
Normal file
66
AdServer/clientbase.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "clientbase.h"
|
||||
|
||||
ClientBase::ClientBase(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ClientBase::~ClientBase()
|
||||
{
|
||||
closeConnection();
|
||||
delete m_socket;
|
||||
}
|
||||
|
||||
|
||||
void ClientBase::closeConnection()
|
||||
{
|
||||
m_socket->disconnectFromHost();
|
||||
}
|
||||
|
||||
|
||||
QString ClientBase::getStatus()
|
||||
{
|
||||
QString s;
|
||||
switch (m_socket->state())
|
||||
{
|
||||
case QAbstractSocket::UnconnectedState :
|
||||
s = trUtf8("not connected");
|
||||
break;
|
||||
case QAbstractSocket::HostLookupState :
|
||||
s = trUtf8("loking for server...");
|
||||
break;
|
||||
case QAbstractSocket::ConnectingState :
|
||||
s = trUtf8("connecting...");
|
||||
break;
|
||||
case QAbstractSocket::ConnectedState :
|
||||
s = trUtf8("connected!");
|
||||
break;
|
||||
case QAbstractSocket::ClosingState :
|
||||
s = trUtf8("disconnecting....");
|
||||
break;
|
||||
default:
|
||||
s = trUtf8("error");
|
||||
}
|
||||
s += trUtf8(" to %1:%2").arg(m_socket->peerAddress().toString()).arg(m_socket->peerPort());
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
void ClientBase::send(const QByteArray &ba)
|
||||
{
|
||||
m_socket->write(ba);
|
||||
}
|
||||
|
||||
|
||||
void ClientBase::readData()
|
||||
{
|
||||
QByteArray ba = m_socket->readAll();
|
||||
if (!ba.isEmpty()) emit receive(ba);
|
||||
|
||||
}
|
||||
|
||||
void ClientBase::Disconnection()
|
||||
{
|
||||
emit disconnected();
|
||||
}
|
||||
36
AdServer/clientbase.h
Normal file
36
AdServer/clientbase.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef CLIENTBASE_H
|
||||
#define CLIENTBASE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTcpSocket>
|
||||
#include <QHostAddress>
|
||||
#include <QByteArray>
|
||||
#include "message.h"
|
||||
|
||||
|
||||
class ClientBase : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ClientBase(QObject *parent = 0);
|
||||
~ClientBase();
|
||||
void closeConnection();
|
||||
QString getStatus();
|
||||
void send(const QByteArray &ba);
|
||||
|
||||
public slots:
|
||||
|
||||
protected:
|
||||
QTcpSocket * m_socket;
|
||||
|
||||
protected slots:
|
||||
virtual void readData();
|
||||
virtual void Disconnection();
|
||||
|
||||
signals:
|
||||
void disconnected();
|
||||
void receive(QByteArray ba);
|
||||
|
||||
};
|
||||
|
||||
#endif // CLIENTBASE_H
|
||||
11
AdServer/connection.cpp
Normal file
11
AdServer/connection.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "connection.h"
|
||||
|
||||
Connection::Connection(int id, QTcpSocket *socket, QObject *parent) :
|
||||
ClientBase(parent)
|
||||
{
|
||||
m_socket = socket;
|
||||
m_id = id;
|
||||
connect(m_socket,SIGNAL(readyRead()),this,SLOT(readData()));
|
||||
connect(m_socket,SIGNAL(disconnected()),this,SLOT(Disconnection()));
|
||||
}
|
||||
|
||||
24
AdServer/connection.h
Normal file
24
AdServer/connection.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef CONNECTION_H
|
||||
#define CONNECTION_H
|
||||
|
||||
#include <QObject>
|
||||
#include "clientbase.h"
|
||||
|
||||
|
||||
class Connection : public ClientBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Connection(int id, QTcpSocket * socket, QObject *parent = 0);
|
||||
int Id() const {return m_id;}
|
||||
|
||||
private:
|
||||
int m_id;
|
||||
|
||||
signals:
|
||||
|
||||
private slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // CONNECTION_H
|
||||
33
AdServer/main.cpp
Normal file
33
AdServer/main.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <QtGui/QApplication>
|
||||
#include "widget.h"
|
||||
//#include "stdafx.h"
|
||||
#include "windows.h"
|
||||
//#include "iostream.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
Widget w;
|
||||
w.show();
|
||||
WCHAR NameBuffer[MAX_PATH];
|
||||
WCHAR SysNameBuffer[MAX_PATH];
|
||||
DWORD VSNumber;
|
||||
DWORD MCLength;
|
||||
DWORD FileSF;
|
||||
|
||||
|
||||
char *x="D:\\";
|
||||
WCHAR b[10];
|
||||
|
||||
swprintf(b, L"%S", x);
|
||||
|
||||
if (GetVolumeInformation(b,NameBuffer, sizeof(NameBuffer),
|
||||
&VSNumber,&MCLength,&FileSF,SysNameBuffer,sizeof(SysNameBuffer)))
|
||||
{
|
||||
qDebug() << QString::fromWCharArray(NameBuffer);
|
||||
qDebug() << QString::fromWCharArray(SysNameBuffer);
|
||||
qDebug() << VSNumber;
|
||||
}
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
37
AdServer/message.h
Normal file
37
AdServer/message.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef MESSAGE_H
|
||||
#define MESSAGE_H
|
||||
|
||||
|
||||
#pragma pack (push, 1)
|
||||
|
||||
struct adMessageHeader
|
||||
{
|
||||
int type;
|
||||
int player;
|
||||
};
|
||||
|
||||
|
||||
struct adMessagePing // type = 1
|
||||
{
|
||||
adMessageHeader header;
|
||||
char name[32];
|
||||
};
|
||||
|
||||
|
||||
struct adMessagePong // type = 2
|
||||
{
|
||||
adMessageHeader header;
|
||||
int playerId;
|
||||
unsigned int seed;
|
||||
};
|
||||
|
||||
|
||||
struct adMessageText // type = 3
|
||||
{
|
||||
adMessageHeader header;
|
||||
char text[256];
|
||||
};
|
||||
|
||||
#pragma pack (pop)
|
||||
|
||||
#endif // MESSAGE_H
|
||||
81
AdServer/release/moc_client.cpp
Normal file
81
AdServer/release/moc_client.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
** Meta object code from reading C++ file 'client.h'
|
||||
**
|
||||
** Created: Tue 8. Jan 13:24:46 2013
|
||||
** by: The Qt Meta Object Compiler version 63 (Qt 4.8.1)
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost!
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../client.h"
|
||||
#if !defined(Q_MOC_OUTPUT_REVISION)
|
||||
#error "The header file 'client.h' doesn't include <QObject>."
|
||||
#elif Q_MOC_OUTPUT_REVISION != 63
|
||||
#error "This file was generated using the moc from 4.8.1. It"
|
||||
#error "cannot be used with the include files from this version of Qt."
|
||||
#error "(The moc has changed too much.)"
|
||||
#endif
|
||||
|
||||
QT_BEGIN_MOC_NAMESPACE
|
||||
static const uint qt_meta_data_Client[] = {
|
||||
|
||||
// content:
|
||||
6, // revision
|
||||
0, // classname
|
||||
0, 0, // classinfo
|
||||
0, 0, // methods
|
||||
0, 0, // properties
|
||||
0, 0, // enums/sets
|
||||
0, 0, // constructors
|
||||
0, // flags
|
||||
0, // signalCount
|
||||
|
||||
0 // eod
|
||||
};
|
||||
|
||||
static const char qt_meta_stringdata_Client[] = {
|
||||
"Client\0"
|
||||
};
|
||||
|
||||
void Client::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
Q_UNUSED(_o);
|
||||
Q_UNUSED(_id);
|
||||
Q_UNUSED(_c);
|
||||
Q_UNUSED(_a);
|
||||
}
|
||||
|
||||
const QMetaObjectExtraData Client::staticMetaObjectExtraData = {
|
||||
0, qt_static_metacall
|
||||
};
|
||||
|
||||
const QMetaObject Client::staticMetaObject = {
|
||||
{ &ClientBase::staticMetaObject, qt_meta_stringdata_Client,
|
||||
qt_meta_data_Client, &staticMetaObjectExtraData }
|
||||
};
|
||||
|
||||
#ifdef Q_NO_DATA_RELOCATION
|
||||
const QMetaObject &Client::getStaticMetaObject() { return staticMetaObject; }
|
||||
#endif //Q_NO_DATA_RELOCATION
|
||||
|
||||
const QMetaObject *Client::metaObject() const
|
||||
{
|
||||
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
|
||||
}
|
||||
|
||||
void *Client::qt_metacast(const char *_clname)
|
||||
{
|
||||
if (!_clname) return 0;
|
||||
if (!strcmp(_clname, qt_meta_stringdata_Client))
|
||||
return static_cast<void*>(const_cast< Client*>(this));
|
||||
return ClientBase::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
int Client::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
_id = ClientBase::qt_metacall(_c, _id, _a);
|
||||
if (_id < 0)
|
||||
return _id;
|
||||
return _id;
|
||||
}
|
||||
QT_END_MOC_NAMESPACE
|
||||
116
AdServer/release/moc_clientbase.cpp
Normal file
116
AdServer/release/moc_clientbase.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
/****************************************************************************
|
||||
** Meta object code from reading C++ file 'clientbase.h'
|
||||
**
|
||||
** Created: Tue 8. Jan 13:24:47 2013
|
||||
** by: The Qt Meta Object Compiler version 63 (Qt 4.8.1)
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost!
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../clientbase.h"
|
||||
#if !defined(Q_MOC_OUTPUT_REVISION)
|
||||
#error "The header file 'clientbase.h' doesn't include <QObject>."
|
||||
#elif Q_MOC_OUTPUT_REVISION != 63
|
||||
#error "This file was generated using the moc from 4.8.1. It"
|
||||
#error "cannot be used with the include files from this version of Qt."
|
||||
#error "(The moc has changed too much.)"
|
||||
#endif
|
||||
|
||||
QT_BEGIN_MOC_NAMESPACE
|
||||
static const uint qt_meta_data_ClientBase[] = {
|
||||
|
||||
// content:
|
||||
6, // revision
|
||||
0, // classname
|
||||
0, 0, // classinfo
|
||||
4, 14, // methods
|
||||
0, 0, // properties
|
||||
0, 0, // enums/sets
|
||||
0, 0, // constructors
|
||||
0, // flags
|
||||
2, // signalCount
|
||||
|
||||
// signals: signature, parameters, type, tag, flags
|
||||
12, 11, 11, 11, 0x05,
|
||||
30, 27, 11, 11, 0x05,
|
||||
|
||||
// slots: signature, parameters, type, tag, flags
|
||||
50, 11, 11, 11, 0x09,
|
||||
61, 11, 11, 11, 0x09,
|
||||
|
||||
0 // eod
|
||||
};
|
||||
|
||||
static const char qt_meta_stringdata_ClientBase[] = {
|
||||
"ClientBase\0\0disconnected()\0ba\0"
|
||||
"receive(QByteArray)\0readData()\0"
|
||||
"Disconnection()\0"
|
||||
};
|
||||
|
||||
void ClientBase::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
if (_c == QMetaObject::InvokeMetaMethod) {
|
||||
Q_ASSERT(staticMetaObject.cast(_o));
|
||||
ClientBase *_t = static_cast<ClientBase *>(_o);
|
||||
switch (_id) {
|
||||
case 0: _t->disconnected(); break;
|
||||
case 1: _t->receive((*reinterpret_cast< QByteArray(*)>(_a[1]))); break;
|
||||
case 2: _t->readData(); break;
|
||||
case 3: _t->Disconnection(); break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const QMetaObjectExtraData ClientBase::staticMetaObjectExtraData = {
|
||||
0, qt_static_metacall
|
||||
};
|
||||
|
||||
const QMetaObject ClientBase::staticMetaObject = {
|
||||
{ &QObject::staticMetaObject, qt_meta_stringdata_ClientBase,
|
||||
qt_meta_data_ClientBase, &staticMetaObjectExtraData }
|
||||
};
|
||||
|
||||
#ifdef Q_NO_DATA_RELOCATION
|
||||
const QMetaObject &ClientBase::getStaticMetaObject() { return staticMetaObject; }
|
||||
#endif //Q_NO_DATA_RELOCATION
|
||||
|
||||
const QMetaObject *ClientBase::metaObject() const
|
||||
{
|
||||
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
|
||||
}
|
||||
|
||||
void *ClientBase::qt_metacast(const char *_clname)
|
||||
{
|
||||
if (!_clname) return 0;
|
||||
if (!strcmp(_clname, qt_meta_stringdata_ClientBase))
|
||||
return static_cast<void*>(const_cast< ClientBase*>(this));
|
||||
return QObject::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
int ClientBase::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
_id = QObject::qt_metacall(_c, _id, _a);
|
||||
if (_id < 0)
|
||||
return _id;
|
||||
if (_c == QMetaObject::InvokeMetaMethod) {
|
||||
if (_id < 4)
|
||||
qt_static_metacall(this, _c, _id, _a);
|
||||
_id -= 4;
|
||||
}
|
||||
return _id;
|
||||
}
|
||||
|
||||
// SIGNAL 0
|
||||
void ClientBase::disconnected()
|
||||
{
|
||||
QMetaObject::activate(this, &staticMetaObject, 0, 0);
|
||||
}
|
||||
|
||||
// SIGNAL 1
|
||||
void ClientBase::receive(QByteArray _t1)
|
||||
{
|
||||
void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
|
||||
QMetaObject::activate(this, &staticMetaObject, 1, _a);
|
||||
}
|
||||
QT_END_MOC_NAMESPACE
|
||||
81
AdServer/release/moc_connection.cpp
Normal file
81
AdServer/release/moc_connection.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
** Meta object code from reading C++ file 'connection.h'
|
||||
**
|
||||
** Created: Tue 8. Jan 13:24:45 2013
|
||||
** by: The Qt Meta Object Compiler version 63 (Qt 4.8.1)
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost!
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../connection.h"
|
||||
#if !defined(Q_MOC_OUTPUT_REVISION)
|
||||
#error "The header file 'connection.h' doesn't include <QObject>."
|
||||
#elif Q_MOC_OUTPUT_REVISION != 63
|
||||
#error "This file was generated using the moc from 4.8.1. It"
|
||||
#error "cannot be used with the include files from this version of Qt."
|
||||
#error "(The moc has changed too much.)"
|
||||
#endif
|
||||
|
||||
QT_BEGIN_MOC_NAMESPACE
|
||||
static const uint qt_meta_data_Connection[] = {
|
||||
|
||||
// content:
|
||||
6, // revision
|
||||
0, // classname
|
||||
0, 0, // classinfo
|
||||
0, 0, // methods
|
||||
0, 0, // properties
|
||||
0, 0, // enums/sets
|
||||
0, 0, // constructors
|
||||
0, // flags
|
||||
0, // signalCount
|
||||
|
||||
0 // eod
|
||||
};
|
||||
|
||||
static const char qt_meta_stringdata_Connection[] = {
|
||||
"Connection\0"
|
||||
};
|
||||
|
||||
void Connection::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
Q_UNUSED(_o);
|
||||
Q_UNUSED(_id);
|
||||
Q_UNUSED(_c);
|
||||
Q_UNUSED(_a);
|
||||
}
|
||||
|
||||
const QMetaObjectExtraData Connection::staticMetaObjectExtraData = {
|
||||
0, qt_static_metacall
|
||||
};
|
||||
|
||||
const QMetaObject Connection::staticMetaObject = {
|
||||
{ &ClientBase::staticMetaObject, qt_meta_stringdata_Connection,
|
||||
qt_meta_data_Connection, &staticMetaObjectExtraData }
|
||||
};
|
||||
|
||||
#ifdef Q_NO_DATA_RELOCATION
|
||||
const QMetaObject &Connection::getStaticMetaObject() { return staticMetaObject; }
|
||||
#endif //Q_NO_DATA_RELOCATION
|
||||
|
||||
const QMetaObject *Connection::metaObject() const
|
||||
{
|
||||
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
|
||||
}
|
||||
|
||||
void *Connection::qt_metacast(const char *_clname)
|
||||
{
|
||||
if (!_clname) return 0;
|
||||
if (!strcmp(_clname, qt_meta_stringdata_Connection))
|
||||
return static_cast<void*>(const_cast< Connection*>(this));
|
||||
return ClientBase::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
int Connection::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
_id = ClientBase::qt_metacall(_c, _id, _a);
|
||||
if (_id < 0)
|
||||
return _id;
|
||||
return _id;
|
||||
}
|
||||
QT_END_MOC_NAMESPACE
|
||||
110
AdServer/release/moc_server.cpp
Normal file
110
AdServer/release/moc_server.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
/****************************************************************************
|
||||
** Meta object code from reading C++ file 'server.h'
|
||||
**
|
||||
** Created: Tue 8. Jan 13:24:44 2013
|
||||
** by: The Qt Meta Object Compiler version 63 (Qt 4.8.1)
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost!
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../server.h"
|
||||
#if !defined(Q_MOC_OUTPUT_REVISION)
|
||||
#error "The header file 'server.h' doesn't include <QObject>."
|
||||
#elif Q_MOC_OUTPUT_REVISION != 63
|
||||
#error "This file was generated using the moc from 4.8.1. It"
|
||||
#error "cannot be used with the include files from this version of Qt."
|
||||
#error "(The moc has changed too much.)"
|
||||
#endif
|
||||
|
||||
QT_BEGIN_MOC_NAMESPACE
|
||||
static const uint qt_meta_data_Server[] = {
|
||||
|
||||
// content:
|
||||
6, // revision
|
||||
0, // classname
|
||||
0, 0, // classinfo
|
||||
4, 14, // methods
|
||||
0, 0, // properties
|
||||
0, 0, // enums/sets
|
||||
0, 0, // constructors
|
||||
0, // flags
|
||||
1, // signalCount
|
||||
|
||||
// signals: signature, parameters, type, tag, flags
|
||||
11, 8, 7, 7, 0x05,
|
||||
|
||||
// slots: signature, parameters, type, tag, flags
|
||||
35, 7, 7, 7, 0x08,
|
||||
51, 7, 7, 7, 0x08,
|
||||
70, 8, 7, 7, 0x08,
|
||||
|
||||
0 // eod
|
||||
};
|
||||
|
||||
static const char qt_meta_stringdata_Server[] = {
|
||||
"Server\0\0ba\0receiveData(QByteArray)\0"
|
||||
"newConnection()\0connectionClosed()\0"
|
||||
"received(QByteArray)\0"
|
||||
};
|
||||
|
||||
void Server::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
if (_c == QMetaObject::InvokeMetaMethod) {
|
||||
Q_ASSERT(staticMetaObject.cast(_o));
|
||||
Server *_t = static_cast<Server *>(_o);
|
||||
switch (_id) {
|
||||
case 0: _t->receiveData((*reinterpret_cast< QByteArray(*)>(_a[1]))); break;
|
||||
case 1: _t->newConnection(); break;
|
||||
case 2: _t->connectionClosed(); break;
|
||||
case 3: _t->received((*reinterpret_cast< QByteArray(*)>(_a[1]))); break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const QMetaObjectExtraData Server::staticMetaObjectExtraData = {
|
||||
0, qt_static_metacall
|
||||
};
|
||||
|
||||
const QMetaObject Server::staticMetaObject = {
|
||||
{ &QObject::staticMetaObject, qt_meta_stringdata_Server,
|
||||
qt_meta_data_Server, &staticMetaObjectExtraData }
|
||||
};
|
||||
|
||||
#ifdef Q_NO_DATA_RELOCATION
|
||||
const QMetaObject &Server::getStaticMetaObject() { return staticMetaObject; }
|
||||
#endif //Q_NO_DATA_RELOCATION
|
||||
|
||||
const QMetaObject *Server::metaObject() const
|
||||
{
|
||||
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
|
||||
}
|
||||
|
||||
void *Server::qt_metacast(const char *_clname)
|
||||
{
|
||||
if (!_clname) return 0;
|
||||
if (!strcmp(_clname, qt_meta_stringdata_Server))
|
||||
return static_cast<void*>(const_cast< Server*>(this));
|
||||
return QObject::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
int Server::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
_id = QObject::qt_metacall(_c, _id, _a);
|
||||
if (_id < 0)
|
||||
return _id;
|
||||
if (_c == QMetaObject::InvokeMetaMethod) {
|
||||
if (_id < 4)
|
||||
qt_static_metacall(this, _c, _id, _a);
|
||||
_id -= 4;
|
||||
}
|
||||
return _id;
|
||||
}
|
||||
|
||||
// SIGNAL 0
|
||||
void Server::receiveData(QByteArray _t1)
|
||||
{
|
||||
void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
|
||||
QMetaObject::activate(this, &staticMetaObject, 0, _a);
|
||||
}
|
||||
QT_END_MOC_NAMESPACE
|
||||
115
AdServer/release/moc_widget.cpp
Normal file
115
AdServer/release/moc_widget.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
/****************************************************************************
|
||||
** Meta object code from reading C++ file 'widget.h'
|
||||
**
|
||||
** Created: Tue 8. Jan 13:24:43 2013
|
||||
** by: The Qt Meta Object Compiler version 63 (Qt 4.8.1)
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost!
|
||||
*****************************************************************************/
|
||||
|
||||
#include "../widget.h"
|
||||
#if !defined(Q_MOC_OUTPUT_REVISION)
|
||||
#error "The header file 'widget.h' doesn't include <QObject>."
|
||||
#elif Q_MOC_OUTPUT_REVISION != 63
|
||||
#error "This file was generated using the moc from 4.8.1. It"
|
||||
#error "cannot be used with the include files from this version of Qt."
|
||||
#error "(The moc has changed too much.)"
|
||||
#endif
|
||||
|
||||
QT_BEGIN_MOC_NAMESPACE
|
||||
static const uint qt_meta_data_Widget[] = {
|
||||
|
||||
// content:
|
||||
6, // revision
|
||||
0, // classname
|
||||
0, 0, // classinfo
|
||||
9, 14, // methods
|
||||
0, 0, // properties
|
||||
0, 0, // enums/sets
|
||||
0, 0, // constructors
|
||||
0, // flags
|
||||
0, // signalCount
|
||||
|
||||
// slots: signature, parameters, type, tag, flags
|
||||
8, 7, 7, 7, 0x08,
|
||||
33, 7, 7, 7, 0x08,
|
||||
60, 7, 7, 7, 0x08,
|
||||
86, 7, 7, 7, 0x08,
|
||||
111, 7, 7, 7, 0x08,
|
||||
134, 7, 7, 7, 0x08,
|
||||
163, 160, 7, 7, 0x08,
|
||||
185, 7, 7, 7, 0x08,
|
||||
205, 7, 7, 7, 0x08,
|
||||
|
||||
0 // eod
|
||||
};
|
||||
|
||||
static const char qt_meta_stringdata_Widget[] = {
|
||||
"Widget\0\0on_bpSetServer_clicked()\0"
|
||||
"on_bpStartServer_clicked()\0"
|
||||
"on_pbStopServer_clicked()\0"
|
||||
"on_pbSetClient_clicked()\0"
|
||||
"on_pbConnect_clicked()\0on_pbDisconnect_clicked()\0"
|
||||
"ba\0onReceive(QByteArray)\0on_bpSend_clicked()\0"
|
||||
"on_leText_returnPressed()\0"
|
||||
};
|
||||
|
||||
void Widget::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
if (_c == QMetaObject::InvokeMetaMethod) {
|
||||
Q_ASSERT(staticMetaObject.cast(_o));
|
||||
Widget *_t = static_cast<Widget *>(_o);
|
||||
switch (_id) {
|
||||
case 0: _t->on_bpSetServer_clicked(); break;
|
||||
case 1: _t->on_bpStartServer_clicked(); break;
|
||||
case 2: _t->on_pbStopServer_clicked(); break;
|
||||
case 3: _t->on_pbSetClient_clicked(); break;
|
||||
case 4: _t->on_pbConnect_clicked(); break;
|
||||
case 5: _t->on_pbDisconnect_clicked(); break;
|
||||
case 6: _t->onReceive((*reinterpret_cast< QByteArray(*)>(_a[1]))); break;
|
||||
case 7: _t->on_bpSend_clicked(); break;
|
||||
case 8: _t->on_leText_returnPressed(); break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const QMetaObjectExtraData Widget::staticMetaObjectExtraData = {
|
||||
0, qt_static_metacall
|
||||
};
|
||||
|
||||
const QMetaObject Widget::staticMetaObject = {
|
||||
{ &QWidget::staticMetaObject, qt_meta_stringdata_Widget,
|
||||
qt_meta_data_Widget, &staticMetaObjectExtraData }
|
||||
};
|
||||
|
||||
#ifdef Q_NO_DATA_RELOCATION
|
||||
const QMetaObject &Widget::getStaticMetaObject() { return staticMetaObject; }
|
||||
#endif //Q_NO_DATA_RELOCATION
|
||||
|
||||
const QMetaObject *Widget::metaObject() const
|
||||
{
|
||||
return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject;
|
||||
}
|
||||
|
||||
void *Widget::qt_metacast(const char *_clname)
|
||||
{
|
||||
if (!_clname) return 0;
|
||||
if (!strcmp(_clname, qt_meta_stringdata_Widget))
|
||||
return static_cast<void*>(const_cast< Widget*>(this));
|
||||
return QWidget::qt_metacast(_clname);
|
||||
}
|
||||
|
||||
int Widget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
|
||||
{
|
||||
_id = QWidget::qt_metacall(_c, _id, _a);
|
||||
if (_id < 0)
|
||||
return _id;
|
||||
if (_c == QMetaObject::InvokeMetaMethod) {
|
||||
if (_id < 9)
|
||||
qt_static_metacall(this, _c, _id, _a);
|
||||
_id -= 9;
|
||||
}
|
||||
return _id;
|
||||
}
|
||||
QT_END_MOC_NAMESPACE
|
||||
80
AdServer/server.cpp
Normal file
80
AdServer/server.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "server.h"
|
||||
|
||||
Server::Server(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
m_server = new QTcpServer(this);
|
||||
next_conn_id = 1;
|
||||
connect(m_server,SIGNAL(newConnection()),this,SLOT(newConnection()));
|
||||
}
|
||||
|
||||
|
||||
QStringList Server::getIpList()
|
||||
{
|
||||
QList<QHostAddress> list;
|
||||
list = QNetworkInterface::allAddresses();
|
||||
QStringList strl;
|
||||
foreach(QHostAddress adr,list) {
|
||||
if (adr.protocol() == QAbstractSocket::IPv4Protocol)
|
||||
strl.append(adr.toString());
|
||||
}
|
||||
return strl;
|
||||
}
|
||||
|
||||
|
||||
void Server::startServer(QHostAddress a)
|
||||
{
|
||||
m_server->listen(a,44461);
|
||||
}
|
||||
|
||||
|
||||
void Server::stopServer()
|
||||
{
|
||||
m_server->close();
|
||||
foreach (Connection * c, clients)
|
||||
c->closeConnection();
|
||||
}
|
||||
|
||||
QString Server::getStatus()
|
||||
{
|
||||
QString s;
|
||||
if (m_server->isListening())
|
||||
s = trUtf8("Running");
|
||||
else
|
||||
s = trUtf8("Stopped");
|
||||
s += "\n";
|
||||
foreach (Connection * c, clients)
|
||||
s += "\n" + c->getStatus();
|
||||
//s += trUtf8("Connections %1").arg(clients.size());
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
void Server::send(const QByteArray &ba)
|
||||
{
|
||||
foreach (Connection * c, clients)
|
||||
c->send(ba);
|
||||
}
|
||||
|
||||
|
||||
void Server::newConnection()
|
||||
{
|
||||
clients.append(new Connection(next_conn_id, m_server->nextPendingConnection()));
|
||||
connect(clients.last(),SIGNAL(disconnected()),this,SLOT(connectionClosed()));
|
||||
connect(clients.last(),SIGNAL(receive(QByteArray)),this,SLOT(received(QByteArray)));
|
||||
next_conn_id++;
|
||||
}
|
||||
|
||||
|
||||
void Server::connectionClosed()
|
||||
{
|
||||
sender()->deleteLater();
|
||||
clients.removeOne((qobject_cast<Connection*>(sender())));
|
||||
}
|
||||
|
||||
|
||||
void Server::received(QByteArray ba)
|
||||
{
|
||||
emit receiveData(ba);
|
||||
send(ba);
|
||||
}
|
||||
37
AdServer/server.h
Normal file
37
AdServer/server.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef SERVER_H
|
||||
#define SERVER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTcpServer>
|
||||
#include <QNetworkInterface>
|
||||
#include <QStringList>
|
||||
#include "connection.h"
|
||||
|
||||
|
||||
class Server : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Server(QObject *parent = 0);
|
||||
QStringList getIpList();
|
||||
void startServer(QHostAddress);
|
||||
void stopServer();
|
||||
QString getStatus();
|
||||
void send(const QByteArray &ba);
|
||||
|
||||
private:
|
||||
QTcpServer * m_server;
|
||||
QList <Connection*> clients;
|
||||
int next_conn_id;
|
||||
|
||||
private slots:
|
||||
void newConnection();
|
||||
void connectionClosed();
|
||||
void received(QByteArray ba);
|
||||
|
||||
signals:
|
||||
void receiveData(QByteArray ba);
|
||||
|
||||
};
|
||||
|
||||
#endif // SERVER_H
|
||||
213
AdServer/ui_widget.h
Normal file
213
AdServer/ui_widget.h
Normal file
@@ -0,0 +1,213 @@
|
||||
/********************************************************************************
|
||||
** Form generated from reading UI file 'widget.ui'
|
||||
**
|
||||
** Created: Tue 8. Jan 13:24:36 2013
|
||||
** by: Qt User Interface Compiler version 4.8.1
|
||||
**
|
||||
** WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||
********************************************************************************/
|
||||
|
||||
#ifndef UI_WIDGET_H
|
||||
#define UI_WIDGET_H
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtGui/QAction>
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QButtonGroup>
|
||||
#include <QtGui/QComboBox>
|
||||
#include <QtGui/QFrame>
|
||||
#include <QtGui/QGridLayout>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QHeaderView>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QListWidget>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
#include <QtGui/QWidget>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class Ui_Widget
|
||||
{
|
||||
public:
|
||||
QGridLayout *gridLayout;
|
||||
QFrame *frameClient;
|
||||
QVBoxLayout *verticalLayout_3;
|
||||
QLineEdit *leIP;
|
||||
QPushButton *pbConnect;
|
||||
QPushButton *pbDisconnect;
|
||||
QLabel *clienStatus;
|
||||
QFrame *frameServer;
|
||||
QVBoxLayout *verticalLayout;
|
||||
QComboBox *cbIPList;
|
||||
QPushButton *bpStartServer;
|
||||
QPushButton *pbStopServer;
|
||||
QLabel *serverStatus;
|
||||
QListWidget *lwText;
|
||||
QFrame *frameMain;
|
||||
QVBoxLayout *verticalLayout_2;
|
||||
QPushButton *bpSetServer;
|
||||
QPushButton *pbSetClient;
|
||||
QFrame *frameSend;
|
||||
QHBoxLayout *horizontalLayout;
|
||||
QLineEdit *leText;
|
||||
QPushButton *bpSend;
|
||||
|
||||
void setupUi(QWidget *Widget)
|
||||
{
|
||||
if (Widget->objectName().isEmpty())
|
||||
Widget->setObjectName(QString::fromUtf8("Widget"));
|
||||
Widget->resize(474, 354);
|
||||
gridLayout = new QGridLayout(Widget);
|
||||
gridLayout->setSpacing(6);
|
||||
gridLayout->setContentsMargins(11, 11, 11, 11);
|
||||
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
|
||||
frameClient = new QFrame(Widget);
|
||||
frameClient->setObjectName(QString::fromUtf8("frameClient"));
|
||||
frameClient->setFrameShape(QFrame::StyledPanel);
|
||||
frameClient->setFrameShadow(QFrame::Raised);
|
||||
verticalLayout_3 = new QVBoxLayout(frameClient);
|
||||
verticalLayout_3->setSpacing(6);
|
||||
verticalLayout_3->setContentsMargins(11, 11, 11, 11);
|
||||
verticalLayout_3->setObjectName(QString::fromUtf8("verticalLayout_3"));
|
||||
leIP = new QLineEdit(frameClient);
|
||||
leIP->setObjectName(QString::fromUtf8("leIP"));
|
||||
|
||||
verticalLayout_3->addWidget(leIP);
|
||||
|
||||
pbConnect = new QPushButton(frameClient);
|
||||
pbConnect->setObjectName(QString::fromUtf8("pbConnect"));
|
||||
|
||||
verticalLayout_3->addWidget(pbConnect);
|
||||
|
||||
pbDisconnect = new QPushButton(frameClient);
|
||||
pbDisconnect->setObjectName(QString::fromUtf8("pbDisconnect"));
|
||||
|
||||
verticalLayout_3->addWidget(pbDisconnect);
|
||||
|
||||
clienStatus = new QLabel(frameClient);
|
||||
clienStatus->setObjectName(QString::fromUtf8("clienStatus"));
|
||||
|
||||
verticalLayout_3->addWidget(clienStatus);
|
||||
|
||||
|
||||
gridLayout->addWidget(frameClient, 1, 0, 1, 1);
|
||||
|
||||
frameServer = new QFrame(Widget);
|
||||
frameServer->setObjectName(QString::fromUtf8("frameServer"));
|
||||
frameServer->setFrameShape(QFrame::StyledPanel);
|
||||
frameServer->setFrameShadow(QFrame::Raised);
|
||||
verticalLayout = new QVBoxLayout(frameServer);
|
||||
verticalLayout->setSpacing(6);
|
||||
verticalLayout->setContentsMargins(11, 11, 11, 11);
|
||||
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
|
||||
cbIPList = new QComboBox(frameServer);
|
||||
cbIPList->setObjectName(QString::fromUtf8("cbIPList"));
|
||||
|
||||
verticalLayout->addWidget(cbIPList);
|
||||
|
||||
bpStartServer = new QPushButton(frameServer);
|
||||
bpStartServer->setObjectName(QString::fromUtf8("bpStartServer"));
|
||||
|
||||
verticalLayout->addWidget(bpStartServer);
|
||||
|
||||
pbStopServer = new QPushButton(frameServer);
|
||||
pbStopServer->setObjectName(QString::fromUtf8("pbStopServer"));
|
||||
|
||||
verticalLayout->addWidget(pbStopServer);
|
||||
|
||||
serverStatus = new QLabel(frameServer);
|
||||
serverStatus->setObjectName(QString::fromUtf8("serverStatus"));
|
||||
|
||||
verticalLayout->addWidget(serverStatus);
|
||||
|
||||
|
||||
gridLayout->addWidget(frameServer, 0, 0, 1, 1);
|
||||
|
||||
lwText = new QListWidget(Widget);
|
||||
lwText->setObjectName(QString::fromUtf8("lwText"));
|
||||
lwText->setProperty("isWrapping", QVariant(true));
|
||||
lwText->setResizeMode(QListView::Adjust);
|
||||
|
||||
gridLayout->addWidget(lwText, 0, 2, 3, 1);
|
||||
|
||||
frameMain = new QFrame(Widget);
|
||||
frameMain->setObjectName(QString::fromUtf8("frameMain"));
|
||||
frameMain->setFrameShape(QFrame::StyledPanel);
|
||||
frameMain->setFrameShadow(QFrame::Raised);
|
||||
verticalLayout_2 = new QVBoxLayout(frameMain);
|
||||
verticalLayout_2->setSpacing(6);
|
||||
verticalLayout_2->setContentsMargins(11, 11, 11, 11);
|
||||
verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
|
||||
bpSetServer = new QPushButton(frameMain);
|
||||
bpSetServer->setObjectName(QString::fromUtf8("bpSetServer"));
|
||||
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
sizePolicy.setHorizontalStretch(0);
|
||||
sizePolicy.setVerticalStretch(0);
|
||||
sizePolicy.setHeightForWidth(bpSetServer->sizePolicy().hasHeightForWidth());
|
||||
bpSetServer->setSizePolicy(sizePolicy);
|
||||
|
||||
verticalLayout_2->addWidget(bpSetServer);
|
||||
|
||||
pbSetClient = new QPushButton(frameMain);
|
||||
pbSetClient->setObjectName(QString::fromUtf8("pbSetClient"));
|
||||
sizePolicy.setHeightForWidth(pbSetClient->sizePolicy().hasHeightForWidth());
|
||||
pbSetClient->setSizePolicy(sizePolicy);
|
||||
|
||||
verticalLayout_2->addWidget(pbSetClient);
|
||||
|
||||
|
||||
gridLayout->addWidget(frameMain, 0, 1, 2, 1);
|
||||
|
||||
frameSend = new QFrame(Widget);
|
||||
frameSend->setObjectName(QString::fromUtf8("frameSend"));
|
||||
frameSend->setFrameShape(QFrame::StyledPanel);
|
||||
frameSend->setFrameShadow(QFrame::Raised);
|
||||
horizontalLayout = new QHBoxLayout(frameSend);
|
||||
horizontalLayout->setSpacing(6);
|
||||
horizontalLayout->setContentsMargins(11, 11, 11, 11);
|
||||
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
|
||||
leText = new QLineEdit(frameSend);
|
||||
leText->setObjectName(QString::fromUtf8("leText"));
|
||||
|
||||
horizontalLayout->addWidget(leText);
|
||||
|
||||
bpSend = new QPushButton(frameSend);
|
||||
bpSend->setObjectName(QString::fromUtf8("bpSend"));
|
||||
|
||||
horizontalLayout->addWidget(bpSend);
|
||||
|
||||
|
||||
gridLayout->addWidget(frameSend, 2, 0, 1, 2);
|
||||
|
||||
|
||||
retranslateUi(Widget);
|
||||
|
||||
QMetaObject::connectSlotsByName(Widget);
|
||||
} // setupUi
|
||||
|
||||
void retranslateUi(QWidget *Widget)
|
||||
{
|
||||
Widget->setWindowTitle(QApplication::translate("Widget", "Widget", 0, QApplication::UnicodeUTF8));
|
||||
leIP->setText(QApplication::translate("Widget", "127.0.0.1", 0, QApplication::UnicodeUTF8));
|
||||
pbConnect->setText(QApplication::translate("Widget", "Connect", 0, QApplication::UnicodeUTF8));
|
||||
pbDisconnect->setText(QApplication::translate("Widget", "Disconnect", 0, QApplication::UnicodeUTF8));
|
||||
clienStatus->setText(QApplication::translate("Widget", "TextLabel", 0, QApplication::UnicodeUTF8));
|
||||
bpStartServer->setText(QApplication::translate("Widget", "Start server", 0, QApplication::UnicodeUTF8));
|
||||
pbStopServer->setText(QApplication::translate("Widget", "Stop server", 0, QApplication::UnicodeUTF8));
|
||||
serverStatus->setText(QApplication::translate("Widget", "TextLabel", 0, QApplication::UnicodeUTF8));
|
||||
bpSetServer->setText(QApplication::translate("Widget", "Server", 0, QApplication::UnicodeUTF8));
|
||||
pbSetClient->setText(QApplication::translate("Widget", "client", 0, QApplication::UnicodeUTF8));
|
||||
bpSend->setText(QApplication::translate("Widget", "Send", 0, QApplication::UnicodeUTF8));
|
||||
} // retranslateUi
|
||||
|
||||
};
|
||||
|
||||
namespace Ui {
|
||||
class Widget: public Ui_Widget {};
|
||||
} // namespace Ui
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // UI_WIDGET_H
|
||||
93
AdServer/widget.cpp
Normal file
93
AdServer/widget.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include "widget.h"
|
||||
#include "ui_widget.h"
|
||||
|
||||
Widget::Widget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::Widget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->frameClient->setVisible(false);
|
||||
ui->frameServer->setVisible(false);
|
||||
ui->frameSend->setVisible(false);
|
||||
ui->lwText->setVisible(false);
|
||||
server = new Server();
|
||||
client = new Client();
|
||||
ui->cbIPList->addItems(server->getIpList());
|
||||
startTimer(40);
|
||||
}
|
||||
|
||||
|
||||
Widget::~Widget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void Widget::timerEvent(QTimerEvent *)
|
||||
{
|
||||
ui->serverStatus->setText(server->getStatus());
|
||||
ui->clienStatus->setText(client->getStatus());
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_bpSetServer_clicked()
|
||||
{
|
||||
ui->frameServer->setVisible(true);
|
||||
ui->lwText->setVisible(true);
|
||||
ui->frameMain->setVisible(false);
|
||||
// ui->frameSend->setVisible(true);
|
||||
connect(server,SIGNAL(receiveData(QByteArray)),this,SLOT(onReceive(QByteArray)));
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_bpStartServer_clicked()
|
||||
{
|
||||
server->startServer(QHostAddress(ui->cbIPList->currentText()));
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_pbStopServer_clicked()
|
||||
{
|
||||
server->stopServer();
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_pbSetClient_clicked()
|
||||
{
|
||||
ui->frameClient->setVisible(true);
|
||||
ui->lwText->setVisible(true);
|
||||
ui->frameMain->setVisible(false);
|
||||
ui->frameSend->setVisible(true);
|
||||
connect(client,SIGNAL(receive(QByteArray)),this,SLOT(onReceive(QByteArray)));
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_pbConnect_clicked()
|
||||
{
|
||||
client->connectToServer(QHostAddress(ui->leIP->text()));
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_pbDisconnect_clicked()
|
||||
{
|
||||
client->closeConnection();
|
||||
}
|
||||
|
||||
|
||||
void Widget::onReceive(QByteArray ba)
|
||||
{
|
||||
ui->lwText->addItem(QString::fromUtf8(ba.data(),ba.size()));
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_bpSend_clicked()
|
||||
{
|
||||
QByteArray ba = ui->leText->text().toUtf8();
|
||||
client->send(ba);
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_leText_returnPressed()
|
||||
{
|
||||
on_bpSend_clicked();
|
||||
}
|
||||
48
AdServer/widget.h
Normal file
48
AdServer/widget.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef WIDGET_H
|
||||
#define WIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "server.h"
|
||||
#include "client.h"
|
||||
|
||||
namespace Ui {
|
||||
class Widget;
|
||||
}
|
||||
|
||||
class Widget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Widget(QWidget *parent = 0);
|
||||
~Widget();
|
||||
|
||||
private slots:
|
||||
void on_bpSetServer_clicked();
|
||||
|
||||
void on_bpStartServer_clicked();
|
||||
|
||||
void on_pbStopServer_clicked();
|
||||
|
||||
void on_pbSetClient_clicked();
|
||||
|
||||
void on_pbConnect_clicked();
|
||||
|
||||
void on_pbDisconnect_clicked();
|
||||
|
||||
void onReceive(QByteArray ba);
|
||||
|
||||
|
||||
void on_bpSend_clicked();
|
||||
|
||||
void on_leText_returnPressed();
|
||||
|
||||
private:
|
||||
Ui::Widget *ui;
|
||||
Server * server;
|
||||
Client * client;
|
||||
|
||||
void timerEvent(QTimerEvent *);
|
||||
};
|
||||
|
||||
#endif // WIDGET_H
|
||||
168
AdServer/widget.ui
Normal file
168
AdServer/widget.ui
Normal file
@@ -0,0 +1,168 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Widget</class>
|
||||
<widget class="QWidget" name="Widget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>474</width>
|
||||
<height>354</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Widget</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QFrame" name="frameClient">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="leIP">
|
||||
<property name="text">
|
||||
<string>127.0.0.1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pbConnect">
|
||||
<property name="text">
|
||||
<string>Connect</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pbDisconnect">
|
||||
<property name="text">
|
||||
<string>Disconnect</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="clienStatus">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QFrame" name="frameServer">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QComboBox" name="cbIPList"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="bpStartServer">
|
||||
<property name="text">
|
||||
<string>Start server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pbStopServer">
|
||||
<property name="text">
|
||||
<string>Stop server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="serverStatus">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2" rowspan="3">
|
||||
<widget class="QListWidget" name="lwText">
|
||||
<property name="isWrapping" stdset="0">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="resizeMode">
|
||||
<enum>QListView::Adjust</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="2">
|
||||
<widget class="QFrame" name="frameMain">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="bpSetServer">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pbSetClient">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>client</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QFrame" name="frameSend">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="leText"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="bpSend">
|
||||
<property name="text">
|
||||
<string>Send</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user