// VisionNW.h: interface for the CVisionNW class.
//
//////////////////////////////////////////////////////////////////////

#pragma once

#include <string>

#include "MySocket.h"

#ifdef _DLLCLASS
#undef _DLLCLASS
#endif

#define _DLLCLASS __declspec(dllexport)

#define MAXSOCKBUF 4096
#define SERVER     TRUE
#define CLIENT     FALSE

class _DLLCLASS CVisionNW
{
public:
    void ResetReceiveBuffer();
    CVisionNW();
    virtual ~CVisionNW();

    void OnClose(int nErrorCode);
    void OnReceive(int nErrorCode);
    void OnSend(int nErrorCode);
    void OnConnect(int nErrorCode);
    void OnAccept(int nErrorCode);

    bool m_bTraceData;

protected:
    BOOL Send(const std::string& strMsg);
    BOOL IsConnectedToServer(void);
    BOOL IsServerActive(void);
    BOOL IsClientConnected(void);
    void Disconnect(void);
    BOOL Connect(int nPort, std::string strServerName, BOOL bServer = TRUE);
    virtual void ReceiveComm(const char* cpcBuffer, int nSize);
    void ProcessMessage(void);

    char m_RcvBuff[MAXSOCKBUF];
    bool m_bDataComplete;
    int m_nBufferPtr;

private:
    std::string m_strServerName;
    BOOL m_bServerActive;
    BOOL m_bConnectedToServer;
    BOOL m_bClientConnected;

    CMySocket m_sListenSocket;
    CMySocket m_sConnectSocket;
    BOOL m_bConnectionType;
    int m_nPort;
};
