mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added some methods to OSCSender and OSCReceiver to allow them to use existing sockets
This commit is contained in:
parent
faa847f443
commit
eff880e01f
4 changed files with 67 additions and 16 deletions
|
|
@ -331,13 +331,12 @@ struct OSCReceiver::Pimpl : private Thread,
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
bool connectToPort (int portNum)
|
||||
bool connectToPort (int portNumber)
|
||||
{
|
||||
if (! disconnect())
|
||||
return false;
|
||||
|
||||
portNumber = portNum;
|
||||
socket = new DatagramSocket (false);
|
||||
socket.setOwned (new DatagramSocket (false));
|
||||
|
||||
if (! socket->bindToPort (portNumber))
|
||||
return false;
|
||||
|
|
@ -346,14 +345,27 @@ struct OSCReceiver::Pimpl : private Thread,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool connectToSocket (DatagramSocket& newSocket)
|
||||
{
|
||||
if (! disconnect())
|
||||
return false;
|
||||
|
||||
socket.setNonOwned (&newSocket);
|
||||
startThread();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool disconnect()
|
||||
{
|
||||
if (socket != nullptr)
|
||||
{
|
||||
signalThreadShouldExit();
|
||||
socket->shutdown();
|
||||
|
||||
if (socket.willDeleteObject())
|
||||
socket->shutdown();
|
||||
|
||||
waitForThreadToExit (10000);
|
||||
socket = nullptr;
|
||||
socket.reset();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -567,8 +579,7 @@ private:
|
|||
Array<std::pair<OSCAddress, OSCReceiver::ListenerWithOSCAddress<OSCReceiver::MessageLoopCallback>*>> listenersWithAddress;
|
||||
Array<std::pair<OSCAddress, OSCReceiver::ListenerWithOSCAddress<OSCReceiver::RealtimeCallback>*>> realtimeListenersWithAddress;
|
||||
|
||||
ScopedPointer<DatagramSocket> socket;
|
||||
int portNumber = 0;
|
||||
OptionalScopedPointer<DatagramSocket> socket;
|
||||
OSCReceiver::FormatErrorHandler formatErrorHandler { nullptr };
|
||||
enum { oscBufferSize = 4098 };
|
||||
|
||||
|
|
@ -590,6 +601,11 @@ bool OSCReceiver::connect (int portNumber)
|
|||
return pimpl->connectToPort (portNumber);
|
||||
}
|
||||
|
||||
bool OSCReceiver::connectToSocket (DatagramSocket& socket)
|
||||
{
|
||||
return pimpl->connectToSocket (socket);
|
||||
}
|
||||
|
||||
bool OSCReceiver::disconnect()
|
||||
{
|
||||
return pimpl->disconnect();
|
||||
|
|
|
|||
|
|
@ -54,6 +54,14 @@ public:
|
|||
*/
|
||||
bool connect (int portNumber);
|
||||
|
||||
/** Connects to a UDP datagram socket that is already set up,
|
||||
and starts listening to OSC packets arriving on this port.
|
||||
Make sure that the object you give it doesn't get deleted while this
|
||||
object is still using it!
|
||||
@returns true if the connection was successful; false otherwise.
|
||||
*/
|
||||
bool connectToSocket (DatagramSocket& socketToUse);
|
||||
|
||||
//==============================================================================
|
||||
/** Disconnects from the currently used UDP port.
|
||||
@returns true if the disconnection was successful; false otherwise.
|
||||
|
|
|
|||
|
|
@ -215,20 +215,31 @@ struct OSCSender::Pimpl
|
|||
if (! disconnect())
|
||||
return false;
|
||||
|
||||
socket = new DatagramSocket (true);
|
||||
socket.setOwned (new DatagramSocket (true));
|
||||
targetHostName = newTargetHost;
|
||||
targetPortNumber = newTargetPort;
|
||||
|
||||
if (socket->bindToPort (0)) // 0 = use any local port assigned by the OS.
|
||||
return true;
|
||||
|
||||
socket = nullptr;
|
||||
socket.reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool connectToSocket (DatagramSocket& newSocket, const String& newTargetHost, int newTargetPort)
|
||||
{
|
||||
if (! disconnect())
|
||||
return false;
|
||||
|
||||
socket.setNonOwned (&newSocket);
|
||||
targetHostName = newTargetHost;
|
||||
targetPortNumber = newTargetPort;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool disconnect()
|
||||
{
|
||||
socket = nullptr;
|
||||
socket.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -273,7 +284,7 @@ private:
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
ScopedPointer<DatagramSocket> socket;
|
||||
OptionalScopedPointer<DatagramSocket> socket;
|
||||
String targetHostName;
|
||||
int targetPortNumber = 0;
|
||||
|
||||
|
|
@ -298,6 +309,11 @@ bool OSCSender::connect (const String& targetHostName, int targetPortNumber)
|
|||
return pimpl->connect (targetHostName, targetPortNumber);
|
||||
}
|
||||
|
||||
bool OSCSender::connectToSocket (DatagramSocket& socket, const String& targetHostName, int targetPortNumber)
|
||||
{
|
||||
return pimpl->connectToSocket (socket, targetHostName, targetPortNumber);
|
||||
}
|
||||
|
||||
bool OSCSender::disconnect()
|
||||
{
|
||||
return pimpl->disconnect();
|
||||
|
|
|
|||
|
|
@ -48,23 +48,34 @@ public:
|
|||
/** Connects to a datagram socket and prepares the socket for sending OSC
|
||||
packets to the specified target.
|
||||
|
||||
Note: the operating system will choose which specific network adapter(s)
|
||||
to bind your socket to, and which local port to use for the sender.
|
||||
|
||||
@param targetHostName The remote host to which messages will be send.
|
||||
@param targetPortNumber The remote UDP port number on which the host will
|
||||
receive the messages.
|
||||
|
||||
@returns true if the connection was successful; false otherwise.
|
||||
|
||||
Note: the operating system will choose which specific network adapter(s)
|
||||
to bind your socket to, and which local port to use for the sender.
|
||||
|
||||
@see send, disconnect.
|
||||
*/
|
||||
bool connect (const String& targetHostName, int targetPortNumber);
|
||||
|
||||
/** Uses an existing datagram socket for sending OSC packets to the specified target.
|
||||
|
||||
@param socket An existing datagram socket. Make sure this doesn't
|
||||
get deleted while this class is still using it!
|
||||
@param targetHostName The remote host to which messages will be send.
|
||||
@param targetPortNumber The remote UDP port number on which the host will
|
||||
receive the messages.
|
||||
|
||||
@returns true if the connection was successful; false otherwise.
|
||||
@see connect, send, disconnect.
|
||||
*/
|
||||
bool connectToSocket (DatagramSocket& socket, const String& targetHostName, int targetPortNumber);
|
||||
|
||||
//==============================================================================
|
||||
/** Disconnects from the currently used UDP port.
|
||||
@returns true if the disconnection was successful; false otherwise.
|
||||
|
||||
@see connect.
|
||||
*/
|
||||
bool disconnect();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue