#ifndef __TCPCONNECTION_H__
#define __TCPCONNECTION_H__ 


#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <string>
#include <unistd.h>
#include <iostream>
#include <string.h>

/// socket object
class tcpconnection
{
 public:
  tcpconnection();
  ~tcpconnection();
  int init( int sock, sockaddr_in &add );

  /// connect to a remote server
  int init( std::string ip, int port );

  /// sends a message in s specific format
  int sendmessage(int id, int sz, char *buf );

  /// writes to the socket
  int write( char *buf, int size );
  /// reads from a socket
  int read( char *buf, int size);
  /// close a socket
  int closesocket();

  int fid()
  {
    return sock;
  }
 private:
  int ready;
  int sock;
  sockaddr_in address;
};

#endif
