67 NanoOcp1Client(juce::String(), 0, callbacksOnMessageThread, threadPriority)
71NanoOcp1Client::NanoOcp1Client(
const juce::String& address,
const int port,
const bool callbacksOnMessageThread,
const juce::Thread::Priority threadPriority) :
150 NanoOcp1Server(juce::String(), 0, callbacksOnMessageThread, threadPriority)
171 if (m_activeConnection)
173 m_activeConnection->disconnect(1000);
174 return !m_activeConnection->isConnected();
182 if (!m_activeConnection)
185 return m_activeConnection->sendData(data);
190 m_activeConnection = std::make_unique<NanoOcp1Client>(m_callbacksOnMessageThread, m_threadPriority);
193 return m_activeConnection.get();
Abstract base class shared by NanoOcp1Client and NanoOcp1Server.
NanoOcp1Base(const juce::String &address, const int port)
const int getPort()
Returns the current target port number.
std::function< void()> onConnectionEstablished
Fired once after a successful TCP connection is established.
void setPort(const int port)
Sets the TCP port number of the remote OCA device. DS100 default: 50014.
std::function< void()> onConnectionLost
Fired when the TCP connection is dropped or a connect attempt fails.
bool processReceivedData(const ByteVector &data)
Called by derived classes when bytes arrive from the socket. Invokes onDataReceived if set; the frame...
void setAddress(const juce::String &address)
Sets the IP address or hostname of the remote OCA device.
const juce::String & getAddress()
Returns the current target address.
std::function< bool(const ByteVector &)> onDataReceived
Fired when a complete OCP.1 frame is received.
OCP.1 TCP client with automatic reconnection.
bool isRunning()
Returns true if start() has been called and stop() has not.
void timerCallback() override
Timer callback — attempts connectToSocket() when not yet connected.
void messageReceived(const ByteVector &message) override
Called by Ocp1Connection for each received OCP.1 frame — invokes onDataReceived.
void connectionMade() override
Called by Ocp1Connection when TCP connect succeeds — invokes onConnectionEstablished.
NanoOcp1Client(const bool callbacksOnMessageThread, const juce::Thread::Priority threadPriority=juce::Thread::Priority::normal)
Constructs a client without an initial address/port. Call setAddress() and setPort() before start().
bool stop() override
Stops the reconnect timer and closes the TCP socket.
bool start() override
Starts the reconnect timer and begins attempting to connect.
void connectionLost() override
Called by Ocp1Connection when TCP connection is lost — invokes onConnectionLost.
~NanoOcp1Client() override
bool sendData(const ByteVector &data) override
Sends serialized OCP.1 bytes over the active TCP connection. The bytes must be a complete,...
OCP.1 TCP server that accepts a single incoming connection at a time.
NanoOcp1Server(const bool callbacksOnMessageThread, const juce::Thread::Priority threadPriority=juce::Thread::Priority::normal)
Constructs a server without an initial bind address/port.
~NanoOcp1Server() override
bool start() override
Binds the socket and starts the accept loop thread.
Ocp1Connection * createConnectionObject() override
Factory method called by the accept loop — creates the NanoOcp1Client peer object for the newly accep...
bool stop() override
Stops the accept loop and closes any active connection.
bool sendData(const ByteVector &data) override
Sends serialized OCP.1 bytes to the currently connected peer. If no peer is connected,...
TCP accept-loop server base class for OCP.1 connections.
bool beginWaitingForSocket(int portNumber, const juce::String &bindAddress=juce::String())
Binds a TCP socket to the given port and starts the accept-loop thread.
Low-level TCP socket manager for a single OCP.1 connection.
bool connectToSocket(const juce::String &hostName, int portNumber, int timeOutMillisecs)
Attempts a TCP connection to the given host and port. Spawns the read thread on success.
void disconnect(int timeoutMs=0, Notify notify=Notify::yes)
Closes the TCP socket and stops the read thread.
bool isConnected() const
Returns true if the TCP socket is currently open.
bool sendMessage(const ByteVector &message)
Sends a complete OCP.1 frame over the TCP socket. Acquires the write lock, then writes all bytes in o...
Minimal AES70 / OCP.1 TCP client/server library built on JUCE.
std::vector< std::uint8_t > ByteVector
Binary buffer type used throughout NanoOcp for all serialized OCP.1 data.