/****************************************************************************************************

		IMCSocket.h
		Copyright: (c) 2001 Eovia Corp. All rights reserved.

		Author:	charles
		Date:	5/16/2005

****************************************************************************************************/

#ifndef __IMCSocket__
#define __IMCSocket__

#if CP_PRAGMA_ONCE
#pragma once
#endif

struct IMCSocket : public IMCUnknown
{
	enum EProtocol
	{
		kTCP,
		kUDP,
		kInvalidProtocol
	};

	// ****************************************************************************
	//								Init
	// 
	/// Initializes the socket.
	/// 
	/// \param protocol    The protocol to use for the socket
	/// \param portNumber  The port number to which the socket should be attached
	/// 
	virtual void MCCOMAPI Init(EProtocol protocol,int32 portNumber) = 0;

	/// broadcast udp message
	///
	virtual void MCCOMAPI SendBroadcast(uint32 broadcastAddress,const TMCString& message) = 0;

	/// binds the socket to its port
	///
	virtual void MCCOMAPI BindToPort() = 0;

	/// wait for data to be available for reading, return false if times out
	///
	virtual boolean MCCOMAPI WaitForReadableData(float timeOutInSeconds) = 0;

	virtual void MCCOMAPI ListenForConnections() = 0;

	// ****************************************************************************
	//								Accept
	// 
	/// Waits for a connection on a socket. Returns a new socket if a connection is
	/// established
	/// 
	/// \param outSocket         
	/// \param timeOutInSeconds  
	/// 
	virtual bool MCCOMAPI Accept(IMCSocket* outSocket,float timeOutInSeconds) = 0;

	virtual bool MCCOMAPI Connect(const char* serverAddress,float timeOut) = 0;

	/// returns the number of characters read
	///
	virtual int32 MCCOMAPI GetData(char* buffer,int32 bufferSize) = 0;

	// 
	virtual int32 MCCOMAPI PutData(const char* buffer,int32 bytesCount) = 0;
	
	// returns true if the socket has been closed
	virtual boolean MCCOMAPI IsClosed() = 0;

	// ****************************************************************************
	//								Close
	// 
	/// Closes the socket.
	/// 
	virtual void MCCOMAPI Close() = 0;
};



#endif
