OpenShot Library | libopenshot-audio
0.2.0
|
A wrapper for a streaming (TCP) socket. More...
#include <juce_Socket.h>
Public Member Functions | |
StreamingSocket () | |
Creates an uninitialised socket. More... | |
~StreamingSocket () | |
Destructor. More... | |
bool | bindToPort (int localPortNumber) |
Binds the socket to the specified local port. More... | |
bool | bindToPort (int localPortNumber, const String &localAddress) |
Binds the socket to the specified local port and local address. More... | |
int | getBoundPort () const noexcept |
Returns the local port number to which this socket is currently bound. More... | |
bool | connect (const String &remoteHostname, int remotePortNumber, int timeOutMillisecs=3000) |
Tries to connect the socket to hostname:port. More... | |
bool | isConnected () const noexcept |
True if the socket is currently connected. More... | |
void | close () |
Closes the connection. More... | |
const String & | getHostName () const noexcept |
Returns the name of the currently connected host. More... | |
int | getPort () const noexcept |
Returns the port number that's currently open. More... | |
bool | isLocal () const noexcept |
True if the socket is connected to this machine rather than over the network. More... | |
int | getRawSocketHandle () const noexcept |
Returns the OS's socket handle that's currently open. More... | |
int | waitUntilReady (bool readyForReading, int timeoutMsecs) |
Waits until the socket is ready for reading or writing. More... | |
int | read (void *destBuffer, int maxBytesToRead, bool blockUntilSpecifiedAmountHasArrived) |
Reads bytes from the socket. More... | |
int | write (const void *sourceBuffer, int numBytesToWrite) |
Writes bytes to the socket from a buffer. More... | |
bool | createListener (int portNumber, const String &localHostName=String()) |
Puts this socket into "listener" mode. More... | |
StreamingSocket * | waitForNextConnection () const |
When in "listener" mode, this waits for a connection and spawns it as a new socket. More... | |
A wrapper for a streaming (TCP) socket.
This allows low-level use of sockets; for an easier-to-use messaging layer on top of sockets, you could also try the InterprocessConnection class.
Definition at line 41 of file juce_Socket.h.
juce::StreamingSocket::StreamingSocket | ( | ) |
Creates an uninitialised socket.
To connect it, use the connect() method, after which you can read() or write() to it.
To wait for other sockets to connect to this one, the createListener() method enters "listener" mode, and can be used to spawn new sockets for each connection that comes along.
Definition at line 435 of file juce_Socket.cpp.
juce::StreamingSocket::~StreamingSocket | ( | ) |
Destructor.
Definition at line 452 of file juce_Socket.cpp.
bool juce::StreamingSocket::bindToPort | ( | int | localPortNumber | ) |
Binds the socket to the specified local port.
Definition at line 481 of file juce_Socket.cpp.
bool juce::StreamingSocket::bindToPort | ( | int | localPortNumber, |
const String & | localAddress | ||
) |
Binds the socket to the specified local port and local address.
If localAddress is not an empty string then the socket will be bound to localAddress as well. This is useful if you would like to bind your socket to a specific network adapter. Note that localAddress must be an IP address assigned to one of your network address otherwise this function will fail.
Definition at line 486 of file juce_Socket.cpp.
|
noexcept |
Returns the local port number to which this socket is currently bound.
This is useful if you need to know to which port the OS has actually bound your socket when calling the constructor or bindToPort with zero as the localPortNumber argument. Returns -1 if the function fails.
Definition at line 493 of file juce_Socket.cpp.
bool juce::StreamingSocket::connect | ( | const String & | remoteHostname, |
int | remotePortNumber, | ||
int | timeOutMillisecs = 3000 |
||
) |
Tries to connect the socket to hostname:port.
If timeOutMillisecs is 0, then this method will block until the operating system rejects the connection (which could take a long time).
Definition at line 498 of file juce_Socket.cpp.
|
inlinenoexcept |
True if the socket is currently connected.
Definition at line 100 of file juce_Socket.h.
void juce::StreamingSocket::close | ( | ) |
Closes the connection.
Definition at line 527 of file juce_Socket.cpp.
|
inlinenoexcept |
Returns the name of the currently connected host.
Definition at line 106 of file juce_Socket.h.
|
inlinenoexcept |
Returns the port number that's currently open.
Definition at line 109 of file juce_Socket.h.
|
noexcept |
True if the socket is connected to this machine rather than over the network.
Definition at line 589 of file juce_Socket.cpp.
References juce::IPAddress::getAllAddresses().
|
inlinenoexcept |
Returns the OS's socket handle that's currently open.
Definition at line 115 of file juce_Socket.h.
int juce::StreamingSocket::waitUntilReady | ( | bool | readyForReading, |
int | timeoutMsecs | ||
) |
Waits until the socket is ready for reading or writing.
If readyForReading is true, it will wait until the socket is ready for reading; if false, it will wait until it's ready for writing.
If the timeout is < 0, it will wait forever, or else will give up after the specified time.
If the socket is ready on return, this returns 1. If it times-out before the socket becomes ready, it returns 0. If an error occurs, it returns -1.
Definition at line 474 of file juce_Socket.cpp.
int juce::StreamingSocket::read | ( | void * | destBuffer, |
int | maxBytesToRead, | ||
bool | blockUntilSpecifiedAmountHasArrived | ||
) |
Reads bytes from the socket.
If blockUntilSpecifiedAmountHasArrived is true, the method will block until maxBytesToRead bytes have been read, (or until an error occurs). If this flag is false, the method will return as much data as is currently available without blocking.
Definition at line 458 of file juce_Socket.cpp.
int juce::StreamingSocket::write | ( | const void * | sourceBuffer, |
int | numBytesToWrite | ||
) |
Writes bytes to the socket from a buffer.
Note that this method will block unless you have checked the socket is ready for writing before calling it (see the waitUntilReady() method).
Definition at line 465 of file juce_Socket.cpp.
bool juce::StreamingSocket::createListener | ( | int | portNumber, |
const String & | localHostName = String() |
||
) |
Puts this socket into "listener" mode.
When in this mode, your thread can call waitForNextConnection() repeatedly, which will spawn new sockets for each new connection, so that these can be handled in parallel by other threads.
portNumber | the port number to listen on |
localHostName | the interface address to listen on - pass an empty string to listen on all addresses |
Definition at line 538 of file juce_Socket.cpp.
StreamingSocket * juce::StreamingSocket::waitForNextConnection | ( | ) | const |
When in "listener" mode, this waits for a connection and spawns it as a new socket.
The object that gets returned will be owned by the caller.
This method can only be called after using createListener().
Definition at line 569 of file juce_Socket.cpp.