Octave: Change default port number and add custom port number to Preferences

This commit is contained in:
Magne Sjaastad
2024-06-03 07:46:58 +02:00
parent 3f535e5b62
commit 1c899df063
35 changed files with 113 additions and 39 deletions

View File

@@ -56,15 +56,24 @@ RiaSocketServer::RiaSocketServer( QObject* parent )
m_nextPendingConnectionTimer->setInterval( 100 );
m_nextPendingConnectionTimer->setSingleShot( true );
if ( !m_tcpServer->listen( QHostAddress::LocalHost, 40001 ) )
int portNumber = riOctavePlugin::defaultPortNumber;
if ( !RiaPreferences::current()->octavePortNumber().isEmpty() )
{
QString txt = "Disabled communication with Octave due to another ResInsight process running.";
portNumber = RiaPreferences::current()->octavePortNumber().toInt();
}
if ( !m_tcpServer->listen( QHostAddress::LocalHost, portNumber ) )
{
QString txt = QString( "Not able to communicate with Octave plugins. Failed to use port number : %1" ).arg( portNumber );
RiaLogging::warning( txt );
return;
}
QString txt = QString( "Octave is using port: %1" ).arg( portNumber );
RiaLogging::info( txt );
connect( m_nextPendingConnectionTimer, SIGNAL( timeout() ), this, SLOT( slotNewClientConnection() ) );
connect( m_tcpServer, SIGNAL( newConnection() ), this, SLOT( slotNewClientConnection() ) );
}

View File

@@ -16,9 +16,21 @@
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <QDataStream>
namespace riOctavePlugin
{
const int qtDataStreamVersion = QDataStream::Qt_4_0;
// https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
// Use a port number in the dynamic/private range (49152-65535)
const int defaultPortNumber = 52025;
inline const std::string portNumberKey()
{
return "RESINSIGHT_OCTAVE_PORT_NUMBER";
}
} // namespace riOctavePlugin