NanoOcp
Minimal AES70 / OCP.1 TCP client/server library for d&b Soundscape devices
Loading...
Searching...
No Matches
NanoOcp1::Ocp1ConnectionServer Class Referenceabstract

TCP accept-loop server base class for OCP.1 connections. More...

#include <Ocp1ConnectionServer.h>

+ Inheritance diagram for NanoOcp1::Ocp1ConnectionServer:
+ Collaboration diagram for NanoOcp1::Ocp1ConnectionServer:

Public Member Functions

 Ocp1ConnectionServer (const juce::Thread::Priority threadPriority=juce::Thread::Priority::normal)
 Constructs the server.
 
 ~Ocp1ConnectionServer () override
 
bool beginWaitingForSocket (int portNumber, const juce::String &bindAddress=juce::String())
 Binds a TCP socket to the given port and starts the accept-loop thread.
 
void stop ()
 Stops the accept-loop thread and closes the listening socket.
 
int getBoundPort () const noexcept
 Returns the port number the server is bound to, or -1 if not listening.
 

Protected Member Functions

virtual Ocp1ConnectioncreateConnectionObject ()=0
 Called by the accept loop each time a new TCP client connects.
 

Detailed Description

TCP accept-loop server base class for OCP.1 connections.

Runs a background juce::Thread that blocks on accept() and calls the pure-virtual createConnectionObject() each time a new TCP client connects. The concrete subclass (NanoOcp1Server) implements createConnectionObject() to return a NanoOcp1Client peer wired to the server's callbacks.

Derived from and inspired by juce::InterprocessConnectionServer, stripped of named-pipe and JUCE IPC handshake support.

See also
NanoOcp1::Ocp1Connection
NanoOcp1::NanoOcp1Server

Definition at line 49 of file Ocp1ConnectionServer.h.

Constructor & Destructor Documentation

◆ Ocp1ConnectionServer()

NanoOcp1::Ocp1ConnectionServer::Ocp1ConnectionServer ( const juce::Thread::Priority  threadPriority = juce::Thread::Priority::normal)

Constructs the server.

Parameters
threadPriorityOS priority of the accept-loop thread.

Definition at line 27 of file Ocp1ConnectionServer.cpp.

◆ ~Ocp1ConnectionServer()

NanoOcp1::Ocp1ConnectionServer::~Ocp1ConnectionServer ( )
override

Definition at line 31 of file Ocp1ConnectionServer.cpp.

References stop().

Member Function Documentation

◆ beginWaitingForSocket()

bool NanoOcp1::Ocp1ConnectionServer::beginWaitingForSocket ( int  portNumber,
const juce::String &  bindAddress = juce::String() 
)

Binds a TCP socket to the given port and starts the accept-loop thread.

Parameters
portNumberLocal TCP port to listen on.
bindAddressLocal IP address to bind to (empty = all interfaces).
Returns
True if the socket was bound and the thread started.

Definition at line 37 of file Ocp1ConnectionServer.cpp.

References stop().

Referenced by NanoOcp1::NanoOcp1Server::start().

◆ createConnectionObject()

virtual Ocp1Connection * NanoOcp1::Ocp1ConnectionServer::createConnectionObject ( )
protectedpure virtual

Called by the accept loop each time a new TCP client connects.

Implementations should create and return a new Ocp1Connection-derived object (typically NanoOcp1Client) configured for the accepted socket. The server takes ownership.

Returns
A heap-allocated Ocp1Connection object for the new client, or nullptr to reject the connection.

Implemented in NanoOcp1::NanoOcp1Server.

◆ getBoundPort()

int NanoOcp1::Ocp1ConnectionServer::getBoundPort ( ) const
noexcept

Returns the port number the server is bound to, or -1 if not listening.

Definition at line 64 of file Ocp1ConnectionServer.cpp.

◆ stop()

void NanoOcp1::Ocp1ConnectionServer::stop ( )

Stops the accept-loop thread and closes the listening socket.

Definition at line 53 of file Ocp1ConnectionServer.cpp.

Referenced by beginWaitingForSocket(), and ~Ocp1ConnectionServer().


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