
#pragma once

/* network includes */
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

class Socket
{
 private:
  int   sock = -1;

 public:
  Socket (char* hostname, char* portname);
  inline ~Socket () { if (valid_connection()) ::close(sock); }

  inline int    read    (char* buf, int nchars) { return ::read(socket,buf,nchars); }
  inline int    write   (char* buf, int nchars) { return ::write(socket,buf,nchars); }
  inline int    valid_connection() { return sock != -1; }
};
