A wrapper for a streaming (TCP) socket. More...
|Creates an uninitialised socket. |
|bool||bindToPort (int localPortNumber)|
|Binds the socket to the specified local port. |
|bool||connect (const String &remoteHostname, int remotePortNumber, int timeOutMillisecs=3000)|
|Tries to connect the socket to hostname:port. |
|bool||isConnected () const noexcept|
|True if the socket is currently connected. |
|Closes the connection. |
|const String &||getHostName () const noexcept|
|Returns the name of the currently connected host. |
|int||getPort () const noexcept|
|Returns the port number that's currently open. |
|bool||isLocal () const noexcept|
|True if the socket is connected to this machine rather than over the network. |
|int||getRawSocketHandle () const noexcept|
|Returns the OS's socket handle that's currently open. |
|int||waitUntilReady (bool readyForReading, int timeoutMsecs) const|
|Waits until the socket is ready for reading or writing. |
|int||read (void *destBuffer, int maxBytesToRead, bool blockUntilSpecifiedAmountHasArrived)|
|Reads bytes from the socket. |
|int||write (const void *sourceBuffer, int numBytesToWrite)|
|Writes bytes to the socket from a buffer. |
|bool||createListener (int portNumber, const String &localHostName=String())|
|Puts this socket into "listener" mode. |
|StreamingSocket *||waitForNextConnection () const|
|When in "listener" mode, this waits for a connection and spawns it as a new socket. |
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.
Binds the socket to the specified local port.
|bool StreamingSocket::connect||(||const String &||remoteHostname,|
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).
True if the socket is currently connected.
Closes the connection.
Returns the name of the currently connected host.
Returns the port number that's currently open.
True if the socket is connected to this machine rather than over the network.
Returns the OS's socket handle that's currently open.
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.
|int StreamingSocket::read||(||void *||destBuffer,|
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.
|int StreamingSocket::write||(||const void *||sourceBuffer,|
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).
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|