46 return withMember (*
this, &SocketOptions::receiveBufferSize, size);
56 return withMember (*
this, &SocketOptions::sendBufferSize, size);
109 : options { optionsIn }
121 bool bindToPort (
int localPortNumber);
134 bool bindToPort (
int localPortNumber,
const String& localAddress);
144 int getBoundPort() const noexcept;
154 bool connect (const
String& remoteHostname,
155 int remotePortNumber,
156 int timeOutMillisecs = 3000);
159 bool isConnected() const noexcept {
return connected; }
168 int getPort() const noexcept {
return portNumber; }
171 bool isLocal() const noexcept;
174 int getRawSocketHandle() const noexcept {
return handle; }
188 int waitUntilReady (
bool readyForReading,
int timeoutMsecs);
200 int read (
void* destBuffer,
int maxBytesToRead,
201 bool blockUntilSpecifiedAmountHasArrived);
210 int write (
const void* sourceBuffer,
int numBytesToWrite);
226 bool createListener (
int portNumber,
const String& localHostName =
String());
245 mutable CriticalSection readLock;
247 StreamingSocket (
const String& hostname,
int portNumber,
int handle,
const SocketOptions& options);
315 bool bindToPort (
int localPortNumber);
328 bool bindToPort (
int localPortNumber,
const String& localAddress);
337 int getBoundPort() const noexcept;
340 int getRawSocketHandle() const noexcept {
return handle; }
354 int waitUntilReady (
bool readyForReading,
int timeoutMsecs);
366 int read (
void* destBuffer,
int maxBytesToRead,
367 bool blockUntilSpecifiedAmountHasArrived);
380 int read (
void* destBuffer,
int maxBytesToRead,
381 bool blockUntilSpecifiedAmountHasArrived,
382 String& senderIPAddress,
int& senderPortNumber);
391 int write (
const String& remoteHostname,
int remotePortNumber,
392 const void* sourceBuffer,
int numBytesToWrite);
415 bool joinMulticast (
const String& multicastIPAddress);
421 bool leaveMulticast (
const String& multicastIPAddress);
427 bool setMulticastLoopbackEnabled (
bool enableLoopback);
438 bool setEnablePortReuse (
bool enabled);
444 bool isBound =
false;
445 String lastBindAddress, lastServerHost;
446 int lastServerPort = -1;
447 void* lastServerAddress =
nullptr;
448 mutable CriticalSection readLock;
A wrapper for a datagram (UDP) socket.
DatagramSocket(bool enableBroadcasting)
Creates a datagram socket.
DatagramSocket()
Creates a datagram socket.
Options used for the configuration of the underlying system socket in the StreamingSocket and Datagra...
SocketOptions withSendBufferSize(int size) const
The provided size will be used to configure the socket's SO_SNDBUF property.
auto getSendBufferSize() const
SocketOptions withReceiveBufferSize(int size) const
The provided size will be used to configure the socket's SO_RCVBUF property.
auto getReceiveBufferSize() const
A wrapper for a streaming (TCP) socket.
int getPort() const noexcept
Returns the port number that's currently open.
const String & getHostName() const noexcept
Returns the name of the currently connected host.
StreamingSocket(const SocketOptions &optionsIn)
Creates an uninitialised socket and allows specifying options related to the configuration of the und...
Object withMember(Object copy, Member OtherObject::*member, Other &&value)
Copies an object, sets one of the copy's members to the specified value, and then returns the copy.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...