|
qavrg 0.0.28
|
#include <qavrgserver.h>
Public Types | |
| typedef QTcpServer | inherited |
Public Slots | |
| void | openNewConnection () |
| void | connectionClosed () |
| void | clientRead () |
| void | finishedCommand (QScriptValue result) |
Signals | |
| void | printMessage (QString msg) |
| void | executeCommand (QString cmd) |
Public Member Functions | |
| QavrgServer (QObject *parent=0) | |
| void | startServer (QHostAddress addr, int port) |
Private Attributes | |
| QTcpSocket * | m_Socket |
Definition at line 11 of file qavrgserver.h.
| typedef QTcpServer QavrgServer::inherited |
Definition at line 17 of file qavrgserver.h.
| QavrgServer::QavrgServer | ( | QObject * | parent = 0 | ) |
Definition at line 7 of file qavrgserver.cpp.
References openNewConnection().
: inherited(parent), m_Socket(NULL) { connect(this, SIGNAL(newConnection()), this, SLOT(openNewConnection())); }
| void QavrgServer::clientRead | ( | ) | [slot] |
Definition at line 55 of file qavrgserver.cpp.
References executeCommand(), m_Socket, and printMessage().
Referenced by openNewConnection().
{
QTextStream ts( m_Socket );
while ( m_Socket->canReadLine() ) {
QString str = ts.readLine();
emit printMessage(tr("Command: %1 received").arg(str));
emit executeCommand(str);
}
}
| void QavrgServer::connectionClosed | ( | ) | [slot] |
Definition at line 49 of file qavrgserver.cpp.
References printMessage().
Referenced by openNewConnection().
{
emit printMessage("Client closed connection");
}
| void QavrgServer::executeCommand | ( | QString | cmd | ) | [signal] |
Referenced by clientRead().
| void QavrgServer::finishedCommand | ( | QScriptValue | result | ) | [slot] |
Definition at line 69 of file qavrgserver.cpp.
References m_Socket, and printMessage().
{
emit printMessage(tr("Result: %1").arg(result.toString()));
if (m_Socket && (m_Socket->isWritable())) {
m_Socket -> write(qPrintable(result.toString()));
}
}
| void QavrgServer::openNewConnection | ( | ) | [slot] |
Definition at line 31 of file qavrgserver.cpp.
References clientRead(), connectionClosed(), m_Socket, and printMessage().
Referenced by QavrgServer().
{
m_Socket = nextPendingConnection();
connect(m_Socket, SIGNAL(disconnected()),
m_Socket, SLOT(deleteLater()));
connect(m_Socket, SIGNAL(readyRead()),
this, SLOT(clientRead()));
emit printMessage(tr("New connection from %1")
.arg(m_Socket->peerAddress().toString()) );
connect(m_Socket, SIGNAL(disconnected()),
this, SLOT(connectionClosed()));
}
| void QavrgServer::printMessage | ( | QString | msg | ) | [signal] |
Referenced by clientRead(), connectionClosed(), finishedCommand(), openNewConnection(), and startServer().
| void QavrgServer::startServer | ( | QHostAddress | addr, |
| int | port | ||
| ) |
Definition at line 16 of file qavrgserver.cpp.
References printMessage().
{
setMaxPendingConnections(1);
if (isListening()) {
close();
}
if (!listen(addr, port)) {
emit printMessage(tr("Failed to bind to address %1 port %2")
.arg(addr.toString()).arg(port));
}
}
QTcpSocket* QavrgServer::m_Socket [private] |
Definition at line 36 of file qavrgserver.h.
Referenced by clientRead(), finishedCommand(), and openNewConnection().
1.7.4