Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.2KB

  1. #ifndef STK_TCPCLIENT_H
  2. #define STK_TCPCLIENT_H
  3. #include "Socket.h"
  4. namespace stk {
  5. /***************************************************/
  6. /*! \class TcpClient
  7. \brief STK TCP socket client class.
  8. This class provides a uniform cross-platform TCP socket client
  9. interface. Methods are provided for reading or writing data
  10. buffers to/from connections.
  11. TCP sockets are reliable and connection-oriented. A TCP socket
  12. client must be connected to a TCP server before data can be sent
  13. or received. Data delivery is guaranteed in order, without loss,
  14. error, or duplication. That said, TCP transmissions tend to be
  15. slower than those using the UDP protocol and data sent with
  16. multiple \e write() calls can be arbitrarily combined by the
  17. underlying system.
  18. The user is responsible for checking the values
  19. returned by the read/write methods. Values
  20. less than or equal to zero indicate a closed
  21. or lost connection or the occurence of an error.
  22. by Perry R. Cook and Gary P. Scavone, 1995-2011.
  23. */
  24. /***************************************************/
  25. class TcpClient : public Socket
  26. {
  27. public:
  28. //! Default class constructor creates a socket client connection to the specified host and port.
  29. /*!
  30. An StkError will be thrown if a socket error occurs during instantiation.
  31. */
  32. TcpClient( int port, std::string hostname = "localhost" );
  33. //! The class destructor closes the socket instance, breaking any existing connections.
  34. ~TcpClient();
  35. //! Connect the socket client to the specified host and port and returns the resulting socket descriptor.
  36. /*!
  37. If the socket client is already connected, that connection is
  38. terminated and a new connection is attempted. An StkError will be
  39. thrown if a socket error occurs.
  40. */
  41. int connect( int port, std::string hostname = "localhost" );
  42. //! Write a buffer over the socket connection. Returns the number of bytes written or -1 if an error occurs.
  43. int writeBuffer(const void *buffer, long bufferSize, int flags = 0);
  44. //! Read a buffer from the socket connection, up to length \e bufferSize. Returns the number of bytes read or -1 if an error occurs.
  45. int readBuffer(void *buffer, long bufferSize, int flags = 0);
  46. protected:
  47. };
  48. } // stk namespace
  49. #endif