qavrg 0.0.28
Public Types | Public Slots | Signals | Public Member Functions | Private Attributes
QavrgServer Class Reference

#include <qavrgserver.h>

List of all members.

Public Types

typedef QTcpServer inherited

Public Slots

void openNewConnection ()
void connectionClosed ()
void clientRead ()
void finishedCommand (QScriptValue result)


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

Detailed Description

Definition at line 11 of file qavrgserver.h.

Member Typedef Documentation

typedef QTcpServer QavrgServer::inherited

Definition at line 17 of file qavrgserver.h.

Constructor & Destructor Documentation

QavrgServer::QavrgServer ( QObject *  parent = 0)

Definition at line 7 of file qavrgserver.cpp.

References openNewConnection().

  : inherited(parent),
  connect(this, SIGNAL(newConnection()),
          this, SLOT(openNewConnection()));

Member Function Documentation

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]
void QavrgServer::startServer ( QHostAddress  addr,
int  port 

Definition at line 16 of file qavrgserver.cpp.

References printMessage().


  if (isListening()) {

  if (!listen(addr, port)) {
    emit printMessage(tr("Failed to bind to address %1 port %2")

Member Data Documentation

QTcpSocket* QavrgServer::m_Socket [private]

Definition at line 36 of file qavrgserver.h.

Referenced by clientRead(), finishedCommand(), and openNewConnection().

The documentation for this class was generated from the following files: