OpenShot Audio Library | OpenShotAudio: juce::StreamingSocket Class Reference

OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
juce::StreamingSocket Class Referencefinal

`#include <juce_Socket.h>`

## Public Types
using | Options = SocketOptions

## Public Member Functions
| StreamingSocket ()
| StreamingSocket (const SocketOptions &optionsIn)
| ~StreamingSocket ()
bool | bindToPort (int localPortNumber)
bool | bindToPort (int localPortNumber, const String &localAddress)
int | getBoundPort () const noexcept
bool | connect (const String &remoteHostname, int remotePortNumber, int timeOutMillisecs=3000)
bool | isConnected () const noexcept
void | close ()
const String & | getHostName () const noexcept
int | getPort () const noexcept
bool | isLocal () const noexcept
int | getRawSocketHandle () const noexcept
int | waitUntilReady (bool readyForReading, int timeoutMsecs)
int | read (void *destBuffer, int maxBytesToRead, bool blockUntilSpecifiedAmountHasArrived)
int | write (const void *sourceBuffer, int numBytesToWrite)
bool | createListener (int portNumber, const String &localHostName=String())
StreamingSocket * | waitForNextConnection () const

## Detailed Description

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.

See also
  DatagramSocket, InterprocessConnection, InterprocessConnectionServer

Definition at line 81 of file juce_Socket.h.

## Member Typedef Documentation

## ◆ Options

using juce::StreamingSocket::Options = SocketOptions

Definition at line 84 of file juce_Socket.h.

## Constructor & Destructor Documentation

## ◆ StreamingSocket() [1/2]

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 484 of file juce_Socket.cpp.

Referenced by waitForNextConnection().

## ◆ StreamingSocket() [2/2]

juce::StreamingSocket::StreamingSocket | ( | const SocketOptions & | optionsIn | ) |
| inlineexplicit

Creates an uninitialised socket and allows specifying options related to the configuration of the underlying 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 108 of file juce_Socket.h.

## ◆ ~StreamingSocket()

juce::StreamingSocket::~StreamingSocket | ( |  | ) |

Destructor.

Definition at line 502 of file juce_Socket.cpp.

## Member Function Documentation

## ◆ bindToPort() [1/2]

bool juce::StreamingSocket::bindToPort | ( | int | localPortNumber | ) |

Binds the socket to the specified local port.

Returns
  true on success; false may indicate that another socket is already bound on the same port

Definition at line 531 of file juce_Socket.cpp.

Referenced by bindToPort().

## ◆ bindToPort() [2/2]

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.

Returns
  true on success; false may indicate that another socket is already bound on the same port

See also
  bindToPort (int localPortNumber), IPAddress::getAllAddresses

Definition at line 536 of file juce_Socket.cpp.

## ◆ close()

void juce::StreamingSocket::close | ( |  | ) |

Closes the connection.

Definition at line 581 of file juce_Socket.cpp.

Referenced by connect(), createListener(), and ~StreamingSocket().

## ◆ connect()

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).

Returns
  true if it succeeds, false if otherwise

See also
  isConnected

Definition at line 548 of file juce_Socket.cpp.

## ◆ createListener()

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.

Parameters

  portNumber | the port number to listen on
  localHostName | the interface address to listen on - pass an empty string to listen on all addresses

Returns
  true if it manages to open the socket successfully

See also
  waitForNextConnection

Definition at line 593 of file juce_Socket.cpp.

## ◆ getBoundPort()

int juce::StreamingSocket::getBoundPort | ( |  | ) | const
| 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 543 of file juce_Socket.cpp.

## ◆ getHostName()

const String & juce::StreamingSocket::getHostName | ( |  | ) | const
| inlinenoexcept

Returns the name of the currently connected host.

Definition at line 165 of file juce_Socket.h.

## ◆ getPort()

int juce::StreamingSocket::getPort | ( |  | ) | const
| inlinenoexcept

Returns the port number that's currently open.

Definition at line 168 of file juce_Socket.h.

## ◆ getRawSocketHandle()

int juce::StreamingSocket::getRawSocketHandle | ( |  | ) | const
| inlinenoexcept

Returns the OS's socket handle that's currently open.

Definition at line 174 of file juce_Socket.h.

## ◆ isConnected()

bool juce::StreamingSocket::isConnected | ( |  | ) | const
| inlinenoexcept

True if the socket is currently connected.

Definition at line 159 of file juce_Socket.h.

Referenced by isLocal().

## ◆ isLocal()

bool juce::StreamingSocket::isLocal | ( |  | ) | const
| noexcept

True if the socket is connected to this machine rather than over the network.

Definition at line 644 of file juce_Socket.cpp.

## ◆ read()

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.

Returns
  the number of bytes read, or -1 if there was an error

See also
  waitUntilReady

Definition at line 508 of file juce_Socket.cpp.

## ◆ waitForNextConnection()

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().

See also
  createListener

Definition at line 624 of file juce_Socket.cpp.

## ◆ waitUntilReady()

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.

Returns
  1 if the socket is ready on return, 0 if it times-out before the socket becomes ready, or -1 if an error occurs

Definition at line 524 of file juce_Socket.cpp.

## ◆ write()

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).

Returns
  the number of bytes written, or -1 if there was an error

Definition at line 515 of file juce_Socket.cpp.

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

- juce_Socket.h
- juce_Socket.cpp