BrowserNetwork::BrowserNetwork(RocketWebBrowser *browser_, quint16 port_) :
    browser(browser_),
    client(0),
    port(port_)
{
    server = new QTcpServer(this);
    if (server->listen(QHostAddress::LocalHost, port))
        connect(server, SIGNAL(newConnection()), SLOT(OnNewConnection()));
    else
        qDebug() << "ERROR - RocketWebBrowser: Network server startup failed!";
}
Exemple #2
0
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);


    m_pPlotWidget = ui->plotWidget;
    m_pPlotWidget->setMargin(4);

    m_pPlotWidget->updateLayout();


    m_pPlotWidget->setFrameStyle(QFrame::NoFrame);
    m_pPlotWidget->setLineWidth(0);
    m_pPlotWidget->setCanvasLineWidth(2);


    m_pPlotWidget->plotLayout()->setAlignCanvasToScales(true);

    QwtPlotGrid *grid = new QwtPlotGrid;
    grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
    grid->attach( m_pPlotWidget);

    m_pPlotWidget->setCanvasBackground(QColor(60, 60, 60));

    m_pPlotWidget->setAxisScale(m_pPlotWidget->xBottom, 0, 10);
    m_pPlotWidget->setAxisScale(m_pPlotWidget->yLeft, 0, 100);

    m_pPlotWidget->replot();



    tcpSocket = NULL;
    tcpServer = new QTcpServer(this);
    if (!tcpServer->listen(QHostAddress::Any, 12345))
    {
        QMessageBox::critical(this, "ResourceViewer",
            "Unable to start the server: " + tcpServer->errorString());
    }
    connect(tcpServer, SIGNAL(newConnection()), this, SLOT(OnNewConnection()));

    qDebug()<< "Starting";
}
bool TMsgCore::openConnection()  // server side
{
  // QHostAddress host = (remoteConnection) ?
  // QHostAddress::AnyQHostAddress::LocalHost : ;

  if (m_tcpServer != 0 && m_tcpServer->serverAddress() == QHostAddress::Any)
    return true;
  if (m_tcpServer != 0) delete m_tcpServer;

  m_tcpServer = new QTcpServer();
  bool ret =
      connect(m_tcpServer, SIGNAL(newConnection()), SLOT(OnNewConnection()));
  // bool listen =
  // m_tcpServer->listen(QString("tmsg")+QString::number(QCoreApplication::applicationPid()));
  bool listen = m_tcpServer->listen(
      QHostAddress::Any,
      TMSG_PORT);  // QString("tmsg")+QString::number(QCoreApplication::applicationPid()));
  if (!listen) {
    QString err = m_tcpServer->errorString();
  }

  assert(ret && listen);
  return true;
}
Exemple #4
0
BOOL CListeningSocket::WaitForConnection( void )
{
   ASSERT_VALID( this );

   if ( m_PortNumberInNetworkByteOrder == 0 )
   {
      return( FALSE );
   }

   if ( m_ServerSocketID == INVALID_SOCKET )
   {
      if ( Open() == FALSE )
      {
         TRACE( "CListeningSocket::WaitForConnection(), Can't open() at line %d of %s\n", __LINE__, __FILE__ );
         return( FALSE );
      }
   }

   SOCKADDR incoming_socket_address;

   int byte_count = 0;

   byte_count = sizeof( incoming_socket_address );

   ::ZeroMemory( &incoming_socket_address, byte_count );

   /*
   ** PROGRAM EXECUTION STOPS HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   **
   ** accept() is a blocking call meaning that the this thread of execution is paused
   ** (ie goes to sleep) until someone on the network connects to us. We will "wake up"
   ** when that happens and continue along our merry way.
   */

   m_SocketID = ::accept( m_ServerSocketID, &incoming_socket_address, &byte_count );

   if ( m_SocketID == INVALID_SOCKET )
   {
      m_ErrorCode = ::WSAGetLastError();
	  return( FALSE );
   }

   /*
   ** The method for actually converting the incoming address to something that is human
   ** readable is either undocumented or extremely poorly documented. Not suprising since
   ** the idea of sockets came out of the Unix world...
   */

   LPSTR dotted_ip_address = (LPSTR) NULL;
    
   struct in_addr internet_address;

   /*
   ** Aren't these structure member names intuitively obvious??
   */

   internet_address.S_un.S_un_b.s_b1 = incoming_socket_address.sa_data[ 2 ];
   internet_address.S_un.S_un_b.s_b2 = incoming_socket_address.sa_data[ 3 ];
   internet_address.S_un.S_un_b.s_b3 = incoming_socket_address.sa_data[ 4 ];
   internet_address.S_un.S_un_b.s_b4 = incoming_socket_address.sa_data[ 5 ];

   dotted_ip_address = ::inet_ntoa( internet_address );

   if ( dotted_ip_address == (LPSTR) NULL )
   {
      m_ErrorCode = WSAEINVAL;
	  return( FALSE );
   }

   ULONG temp_long = 0L;

   temp_long = ::inet_addr( (LPCSTR) dotted_ip_address );

   if ( temp_long == INADDR_NONE )
   {
      m_ErrorCode = WSAEINVAL;
	  return( FALSE );
   }

   LPHOSTENT host_entry_p = (LPHOSTENT) NULL;

   host_entry_p = ::gethostbyaddr( (const char *) &temp_long, 4, PF_INET );

   if ( host_entry_p == (LPHOSTENT) NULL )
   {
      m_ErrorCode = ::WSAGetLastError();
	  return( FALSE );
   }

   TRACE( "%s (%s) just connected to us\n", host_entry_p->h_name, (const char *) dotted_ip_address );

   SetAddress( dotted_ip_address );

   OnNewConnection( m_SocketID, Name, dotted_ip_address );

   return( TRUE );
}