/**
 * \file ServerSocket.h
 * \date 08.05.2002
 *
 * Interface for the ServerSocket class
 */

#ifndef MODULES_SERVERSOCKET_H
#define MODULES_SERVERSOCKET_H

#include "Common/Interfaces/Communication.h"
#include "Common/Interfaces/MsgProcess.h"
#include "Common/Module.h"
#include "Common/Main.h"

#ifdef WIN32
#	include <winsock.h>
#else
#	include <netinet/in.h>
#endif

/// Size of the message buffer
#define BUFFERSIZE 8192

/**
 * \class ServerSocket
 * \author Daniel Novomesky
 * \author Marek Lehuta
 * \author Matus Horvath
 * \brief Communication task module
 *
 * Communicates with the soccer server using UDP
 */

class ServerSocket : public Module, public CommunicationInterface
{
public:
// Construction and destruction
	ServerSocket();
	virtual ~ServerSocket();

// Operations
	virtual int Init(int argc, char** argv, int task = -1);
	virtual void Run(int iTask = -1);

	virtual int SetServer(const char* addr, unsigned port);

	virtual int Connect(const char* msg = NULL);
	virtual int SendMsg(const char* msg);
	virtual int ReceiveMsg();
	virtual int Disconnect(const char* msg = NULL);

	virtual Interface* GetInterface(int task = -1) const;

protected:

private:
	char message[BUFFERSIZE];			///< buffer for received messages
	MsgProcessInterface* parser;
    // GP
//   	MsgProcessInterface* clangparser;
	bool connected;
	int sock;							///< socket for communication
	struct sockaddr_in address;			///< server address

};

#endif // MODULES_SERVERSOCKET_H
