Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
67d360f
Add --enabletcp option for server
softins Jan 21, 2025
3513a6e
Initial skeleton for TCP protocol server
softins Mar 22, 2024
4e513ce
Add handling of CL msgs for Server and client list
softins Mar 25, 2024
174eb50
Create CLM_TCP_SUPPORTED and related methods
softins Jan 21, 2025
0ae51e2
Add CLM_TCP_SUPPORTED message generation when TCP enabled
softins Mar 9, 2026
a8baca9
Add flag to request TCP client use
softins Mar 16, 2026
0e0eeac
Add handlers for TCP Supported message
softins Mar 16, 2026
900f323
Propagate TCP client flag down to OnSendCLProtMessage
softins Mar 16, 2026
fa575d8
Delete QTcpServer object when done
softins Mar 19, 2026
d04f978
Added some debug output
softins Mar 20, 2026
dfcd055
Update copyright years
softins Mar 20, 2026
a1d0c91
Separate CTcpConnection code from CTcpServer
softins Mar 21, 2026
e369e97
Make CTcpConnection members private
softins Mar 22, 2026
fb6150c
Add client-side TCP code
softins Mar 23, 2026
031ce5c
Request server list via TCP if required
softins Mar 23, 2026
3a12b7c
Add message context parameter for CLM_TCP_SUPPORTED
softins Mar 25, 2026
d939e5b
Add Qt version check for errorOccurred()
softins Mar 25, 2026
ad58f5e
Fetch client list over TCP when necessary for a server
softins Mar 26, 2026
7813a29
Create CLM_CLIENT_ID and related methods
softins Apr 1, 2026
7f824bf
Add OnClientIDReceived slot to CChannel
softins Apr 1, 2026
0d26acd
Skeleton support for connected mode TCP
softins Apr 1, 2026
aa09415
Move TCP debug message from connectdlg to client
softins Apr 2, 2026
b7b4cdc
Add missing return
softins Apr 2, 2026
29d7fab
Remove unneeded #include from tcpconnection
softins Apr 2, 2026
536be3b
Send client list via TCP when connection available
softins Apr 4, 2026
4256633
Add skeleton handler for CLClientID to CServer
softins Apr 4, 2026
091d922
Add disconnecFromHost method to CTcpConnection
softins Apr 5, 2026
ac85be0
Mods to CTcpConnection for future use
softins Apr 5, 2026
868416e
In server, link TCP channel to UDP channel by client ID
softins Apr 5, 2026
23e9c36
Replace boolean TCP flag with multimode enum
softins Apr 5, 2026
5a100b9
Add creation of session-long TCP connection
softins Apr 6, 2026
19a90e6
Route CLConnClientList depending on whether connected
softins Apr 6, 2026
b71df91
Be specific about bDisconAfterRecv for TCP
softins Apr 7, 2026
08abf30
Rework TCP session-mode connection
softins Apr 7, 2026
5850507
Minor comment updates
softins Apr 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Jamulus.pro
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ HEADERS += src/plugins/audioreverb.h \
src/serverlogging.h \
src/settings.h \
src/socket.h \
src/tcpserver.h \
src/tcpconnection.h \
src/util.h \
src/recorder/jamrecorder.h \
src/recorder/creaperproject.h \
Expand Down Expand Up @@ -507,6 +509,8 @@ SOURCES += src/plugins/audioreverb.cpp \
src/settings.cpp \
src/signalhandler.cpp \
src/socket.cpp \
src/tcpserver.cpp \
src/tcpconnection.cpp \
src/util.cpp \
src/recorder/jamrecorder.cpp \
src/recorder/creaperproject.cpp \
Expand Down
25 changes: 24 additions & 1 deletion src/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

// CChannel implementation *****************************************************
CChannel::CChannel ( const bool bNIsServer ) :
pTcpConnection ( nullptr ),
vecfGains ( MAX_NUM_CHANNELS, 1.0f ),
vecfPannings ( MAX_NUM_CHANNELS, 0.5f ),
iCurSockBufNumFrames ( INVALID_INDEX ),
Expand Down Expand Up @@ -81,7 +82,7 @@ CChannel::CChannel ( const bool bNIsServer ) :

QObject::connect ( &Protocol, &CProtocol::ChangeChanPan, this, &CChannel::OnChangeChanPan );

QObject::connect ( &Protocol, &CProtocol::ClientIDReceived, this, &CChannel::ClientIDReceived );
QObject::connect ( &Protocol, &CProtocol::ClientIDReceived, this, &CChannel::OnClientIDReceived );

QObject::connect ( &Protocol, &CProtocol::MuteStateHasChangedReceived, this, &CChannel::MuteStateHasChangedReceived );

Expand Down Expand Up @@ -712,3 +713,25 @@ void CChannel::UpdateSocketBufferSize()
SetSockBufNumFrames ( SockBuf.GetAutoSetting(), true );
}
}

void CChannel::OnClientIDReceived ( int iChanID )
{
qDebug() << Q_FUNC_INFO << "iChanID =" << iChanID;
emit ClientIDReceived ( iChanID );
}

void CChannel::CreateConClientListMes ( const CVector<CChannelInfo>& vecChanInfo, CProtocol& ConnLessProtocol )
{
if ( pTcpConnection )
{
qDebug() << "- sending client list via TCP";

ConnLessProtocol.CreateCLConnClientsListMes ( InetAddr, vecChanInfo, pTcpConnection );
}
else
{
qDebug() << "- sending client list via UDP";

Protocol.CreateConClientListMes ( vecChanInfo );
}
}
15 changes: 10 additions & 5 deletions src/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class CChannel : public QObject
void SetAddress ( const CHostAddress& NAddr ) { InetAddr = NAddr; }
const CHostAddress& GetAddress() const { return InetAddr; }

void SetTcpConnection ( CTcpConnection* pConnection ) { pTcpConnection = pConnection; }
CTcpConnection* GetTcpConnection() { return pTcpConnection; }

void ResetInfo()
{
bIsIdentified = false;
Expand Down Expand Up @@ -161,7 +164,7 @@ class CChannel : public QObject
void CreateReqChannelLevelListMes() { Protocol.CreateReqChannelLevelListMes(); }
//### TODO: END ###//

void CreateConClientListMes ( const CVector<CChannelInfo>& vecChanInfo ) { Protocol.CreateConClientListMes ( vecChanInfo ); }
void CreateConClientListMes ( const CVector<CChannelInfo>& vecChanInfo, CProtocol& ConnLessProtocol );

void CreateRecorderStateMes ( const ERecorderState eRecorderState ) { Protocol.CreateRecorderStateMes ( eRecorderState ); }

Expand All @@ -186,7 +189,8 @@ class CChannel : public QObject
}

// connection parameters
CHostAddress InetAddr;
CHostAddress InetAddr;
CTcpConnection* pTcpConnection;

// channel info
CChannelCoreInfo ChannelInfo;
Expand Down Expand Up @@ -255,11 +259,12 @@ public slots:
PutProtocolData ( iRecCounter, iRecID, vecbyMesBodyData, RecHostAddr );
}

void OnProtocolCLMessageReceived ( int iRecID, CVector<uint8_t> vecbyMesBodyData, CHostAddress RecHostAddr )
void OnProtocolCLMessageReceived ( int iRecID, CVector<uint8_t> vecbyMesBodyData, CHostAddress RecHostAddr, CTcpConnection* pTcpConnection )
{
emit DetectedCLMessage ( vecbyMesBodyData, iRecID, RecHostAddr );
emit DetectedCLMessage ( vecbyMesBodyData, iRecID, RecHostAddr, pTcpConnection );
}

void OnClientIDReceived ( int iChanID );
void OnNewConnection() { emit NewConnection(); }

signals:
Expand All @@ -282,7 +287,7 @@ public slots:
void RecorderStateReceived ( ERecorderState eRecorderState );
void Disconnected();

void DetectedCLMessage ( CVector<uint8_t> vecbyMesBodyData, int iRecID, CHostAddress RecHostAddr );
void DetectedCLMessage ( CVector<uint8_t> vecbyMesBodyData, int iRecID, CHostAddress RecHostAddr, CTcpConnection* pTcpConnection );

void ParseMessageBody ( CVector<uint8_t> vecbyMesBodyData, int iRecCounter, int iRecID );
};
118 changes: 113 additions & 5 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ CClient::CClient ( const quint16 iPortNumber,

QObject::connect ( &ConnLessProtocol, &CProtocol::CLRedServerListReceived, this, &CClient::CLRedServerListReceived );

QObject::connect ( &ConnLessProtocol, &CProtocol::CLConnClientsListMesReceived, this, &CClient::CLConnClientsListMesReceived );
QObject::connect ( &ConnLessProtocol, &CProtocol::CLTcpSupported, this, &CClient::OnCLTcpSupported );

QObject::connect ( &ConnLessProtocol, &CProtocol::CLConnClientsListMesReceived, this, &CClient::OnCLConnClientsListMesReceived );

QObject::connect ( &ConnLessProtocol, &CProtocol::CLPingReceived, this, &CClient::OnCLPingReceived );

Expand Down Expand Up @@ -249,11 +251,58 @@ void CClient::OnSendProtMessage ( CVector<uint8_t> vecMessage )
Socket.SendPacket ( vecMessage, Channel.GetAddress() );
}

void CClient::OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecMessage )
void CClient::OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecMessage, CTcpConnection* pTcpConnection, enum EProtoMode eProtoMode )
{
if ( pTcpConnection )
{
qWarning() << "Client send cannot use TCP server";
return;
}

// the protocol queries me to call the function to send the message
// send it through the network
Socket.SendPacket ( vecMessage, InetAddr );
if ( eProtoMode != PROTO_UDP )
{
// create a TCP client connection and send message
QTcpSocket* pSocket = new QTcpSocket ( this );

#if QT_VERSION >= QT_VERSION_CHECK( 5, 15, 0 )
# define ERRORSIGNAL &QTcpSocket::errorOccurred
#else
# define ERRORSIGNAL QOverload<QAbstractSocket::SocketError>::of ( &QAbstractSocket::error )
#endif
connect ( pSocket, ERRORSIGNAL, this, [this, pSocket] ( QAbstractSocket::SocketError err ) {
Q_UNUSED ( err );

qWarning() << "- TCP connection error:" << pSocket->errorString();
// may want to specifically handle ConnectionRefusedError?
pSocket->deleteLater();
} );

connect ( pSocket, &QTcpSocket::connected, this, [this, pSocket, InetAddr, vecMessage, eProtoMode]() {
// connection succeeded, give it to a CTcpConnection
CTcpConnection* pTcpConnection = new CTcpConnection ( pSocket,
InetAddr,
nullptr,
&Channel,
eProtoMode == PROTO_TCP_LONG ); // client connection, will self-delete on disconnect

if ( eProtoMode == PROTO_TCP_LONG )
{
Channel.SetTcpConnection ( pTcpConnection ); // link session connection with channel
}

pTcpConnection->write ( (const char*) &( (CVector<uint8_t>) vecMessage )[0], vecMessage.Size() );

// the CTcpConnection object will pass the reply back up to CClient::Channel
} );

pSocket->connectToHost ( InetAddr.InetAddr, InetAddr.iPort );
}
else
{
Socket.SendPacket ( vecMessage, InetAddr );
}
}

void CClient::OnInvalidPacketReceived ( CHostAddress RecHostAddr )
Expand All @@ -268,10 +317,10 @@ void CClient::OnInvalidPacketReceived ( CHostAddress RecHostAddr )
}
}

void CClient::OnDetectedCLMessage ( CVector<uint8_t> vecbyMesBodyData, int iRecID, CHostAddress RecHostAddr )
void CClient::OnDetectedCLMessage ( CVector<uint8_t> vecbyMesBodyData, int iRecID, CHostAddress RecHostAddr, CTcpConnection* pTcpConnection )
{
// connection less messages are always processed
ConnLessProtocol.ParseConnectionLessMessageBody ( vecbyMesBodyData, iRecID, RecHostAddr );
ConnLessProtocol.ParseConnectionLessMessageBody ( vecbyMesBodyData, iRecID, RecHostAddr, pTcpConnection );
}

void CClient::OnJittBufSizeChanged ( int iNewJitBufSize )
Expand Down Expand Up @@ -975,6 +1024,16 @@ void CClient::OnClientIDReceived ( int iServerChanID )
ClearClientChannels();
}

// if TCP Supported has been received, make TCP connection to server
iClientID = iServerChanID; // for sending back to server over TCP

if ( bTcpSupported )
{
// *** Make TCP connection
qDebug() << Q_FUNC_INFO << "need to make TCP connection for" << iClientID;
ConnLessProtocol.CreateCLClientIDMes ( Channel.GetAddress(), iClientID, PROTO_TCP_LONG ); // create persistent TCP connection
}

// allocate and map client-side channel 0
int iChanID = FindClientChannel ( iServerChanID, true ); // should always return channel 0

Expand All @@ -989,11 +1048,52 @@ void CClient::OnClientIDReceived ( int iServerChanID )
emit ClientIDReceived ( iChanID );
}

void CClient::OnCLTcpSupported ( CHostAddress InetAddr, int iID )
{
qDebug() << "- TCP supported at server" << InetAddr.toString() << "for ID =" << iID;

if ( iID != PROTMESSID_CLM_CLIENT_ID )
{
emit CLTcpSupported ( InetAddr, iID ); // pass to connect dialog
return;
}

// if client ID already received, make TCP connection to server
bTcpSupported = true;

if ( iClientID != INVALID_INDEX )
{
// *** Make TCP connection
qDebug() << Q_FUNC_INFO << "need to make TCP connection for" << iClientID;
Q_ASSERT ( InetAddr == Channel.GetAddress() );
ConnLessProtocol.CreateCLClientIDMes ( InetAddr, iClientID, PROTO_TCP_LONG ); // create persistent TCP connection
}
}

void CClient::OnCLConnClientsListMesReceived ( CHostAddress InetAddr, CVector<CChannelInfo> vecChanInfo, CTcpConnection* pTcpConnection )
{
// test if we are receiving for the connect dialog or a connected session
if ( pTcpConnection && pTcpConnection->IsSession() )
{
qDebug() << "- sending client list to client dialog";
OnConClientListMesReceived ( vecChanInfo ); // connected session
}
else
{
qDebug() << "- sending client list to connect dialog";
emit CLConnClientsListMesReceived ( InetAddr, vecChanInfo ); // connect dialog
}
}

void CClient::Start()
{
// init object
Init();

// clear TCP info
iClientID = INVALID_INDEX;
bTcpSupported = false;

// initialise client channels
ClearClientChannels();

Expand All @@ -1014,6 +1114,14 @@ void CClient::Stop()
// stop audio interface
Sound.Stop();

// close any session TCP connection
CTcpConnection* pTcpConnection = Channel.GetTcpConnection();
if ( pTcpConnection )
{
Channel.SetTcpConnection ( nullptr );
pTcpConnection->disconnectFromHost();
}

// disable channel
Channel.SetEnable ( false );

Expand Down
22 changes: 18 additions & 4 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,15 @@ class CClient : public QObject

void CreateCLServerListReqVerAndOSMes ( const CHostAddress& InetAddr ) { ConnLessProtocol.CreateCLReqVersionAndOSMes ( InetAddr ); }

void CreateCLServerListReqConnClientsListMes ( const CHostAddress& InetAddr ) { ConnLessProtocol.CreateCLReqConnClientsListMes ( InetAddr ); }
void CreateCLServerListReqConnClientsListMes ( const CHostAddress& InetAddr, enum EProtoMode eProtoMode )
{
ConnLessProtocol.CreateCLReqConnClientsListMes ( InetAddr, eProtoMode );
}

void CreateCLReqServerListMes ( const CHostAddress& InetAddr ) { ConnLessProtocol.CreateCLReqServerListMes ( InetAddr ); }
void CreateCLReqServerListMes ( const CHostAddress& InetAddr, enum EProtoMode eProtoMode )
{
ConnLessProtocol.CreateCLReqServerListMes ( InetAddr, eProtoMode );
}

int EstimatedOverallDelay ( const int iPingTimeMs );

Expand Down Expand Up @@ -422,12 +428,16 @@ class CClient : public QObject
int maxGainOrPanId;
int iCurPingTime;

// for TCP protocol support
bool bTcpSupported;
int iClientID;

protected slots:
void OnHandledSignal ( int sigNum );
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
void OnInvalidPacketReceived ( CHostAddress RecHostAddr );

void OnDetectedCLMessage ( CVector<uint8_t> vecbyMesBodyData, int iRecID, CHostAddress RecHostAddr );
void OnDetectedCLMessage ( CVector<uint8_t> vecbyMesBodyData, int iRecID, CHostAddress RecHostAddr, CTcpConnection* pTcpConnection );

void OnReqJittBufSize() { CreateServerJitterBufferMessage(); }
void OnJittBufSizeChanged ( int iNewJitBufSize );
Expand All @@ -441,8 +451,9 @@ protected slots:
}
}
void OnCLPingReceived ( CHostAddress InetAddr, int iMs );
void OnCLTcpSupported ( CHostAddress InetAddr, int iID );

void OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecMessage );
void OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecMessage, CTcpConnection* pTcpConnection, enum EProtoMode eProtoMode );

void OnCLPingWithNumClientsReceived ( CHostAddress InetAddr, int iMs, int iNumClients );

Expand All @@ -456,6 +467,7 @@ protected slots:
void OnMuteStateHasChangedReceived ( int iServerChanID, bool bIsMuted );
void OnCLChannelLevelListReceived ( CHostAddress InetAddr, CVector<uint16_t> vecLevelList );
void OnConClientListMesReceived ( CVector<CChannelInfo> vecChanInfo );
void OnCLConnClientsListMesReceived ( CHostAddress InetAddr, CVector<CChannelInfo> vecChanInfo, CTcpConnection* pTcpConnection );

signals:
void ConClientListMesReceived ( CVector<CChannelInfo> vecChanInfo );
Expand All @@ -471,6 +483,8 @@ protected slots:

void CLRedServerListReceived ( CHostAddress InetAddr, CVector<CServerInfo> vecServerInfo );

void CLTcpSupported ( CHostAddress InetAddr, int iID );

void CLConnClientsListMesReceived ( CHostAddress InetAddr, CVector<CChannelInfo> vecChanInfo );

void CLPingTimeWithNumClientsReceived ( CHostAddress InetAddr, int iPingTime, int iNumClients );
Expand Down
2 changes: 2 additions & 0 deletions src/clientdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ CClientDlg::CClientDlg ( CClient* pNCliP,

QObject::connect ( pClient, &CClient::CLRedServerListReceived, this, &CClientDlg::OnCLRedServerListReceived );

QObject::connect ( pClient, &CClient::CLTcpSupported, this, &CClientDlg::OnCLTcpSupported );

QObject::connect ( pClient, &CClient::CLConnClientsListMesReceived, this, &CClientDlg::OnCLConnClientsListMesReceived );

QObject::connect ( pClient, &CClient::CLPingTimeWithNumClientsReceived, this, &CClientDlg::OnCLPingTimeWithNumClientsReceived );
Expand Down
9 changes: 7 additions & 2 deletions src/clientdlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,16 @@ public slots:

void OnNewLocalInputText ( QString strChatText ) { pClient->CreateChatTextMes ( strChatText ); }

void OnReqServerListQuery ( CHostAddress InetAddr ) { pClient->CreateCLReqServerListMes ( InetAddr ); }
void OnReqServerListQuery ( CHostAddress InetAddr, enum EProtoMode eProtoMode ) { pClient->CreateCLReqServerListMes ( InetAddr, eProtoMode ); }

void OnCreateCLServerListPingMes ( CHostAddress InetAddr ) { pClient->CreateCLServerListPingMes ( InetAddr ); }

void OnCreateCLServerListReqVerAndOSMes ( CHostAddress InetAddr ) { pClient->CreateCLServerListReqVerAndOSMes ( InetAddr ); }

void OnCreateCLServerListReqConnClientsListMes ( CHostAddress InetAddr ) { pClient->CreateCLServerListReqConnClientsListMes ( InetAddr ); }
void OnCreateCLServerListReqConnClientsListMes ( CHostAddress InetAddr, enum EProtoMode eProtoMode )
{
pClient->CreateCLServerListReqConnClientsListMes ( InetAddr, eProtoMode );
}

void OnCLServerListReceived ( CHostAddress InetAddr, CVector<CServerInfo> vecServerInfo )
{
Expand All @@ -220,6 +223,8 @@ public slots:
ConnectDlg.SetServerList ( InetAddr, vecServerInfo, true );
}

void OnCLTcpSupported ( CHostAddress InetAddr, int iID ) { ConnectDlg.SetTcpSupported ( InetAddr, iID ); }

void OnCLConnClientsListMesReceived ( CHostAddress InetAddr, CVector<CChannelInfo> vecChanInfo )
{
ConnectDlg.SetConnClientsList ( InetAddr, vecChanInfo );
Expand Down
2 changes: 1 addition & 1 deletion src/clientrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CClientSettings* pSettings, CRpcServe
if ( NetworkUtil::ParseNetworkAddress ( jsonDirectoryIp.toString(), haDirectoryAddress, false ) )
{
// send the request for the server list
pClient->CreateCLReqServerListMes ( haDirectoryAddress );
pClient->CreateCLReqServerListMes ( haDirectoryAddress, PROTO_UDP );
response["result"] = "ok";
}
else
Expand Down
Loading
Loading