/******************************************************************************
|
* FILE: TcpTransport.h
|
* Description:
|
* Interface for the TCP transport class.
|
*
|
* Modified Code History
|
* Mark Date By Modification Reason
|
*******************************************************************************
|
* 01 2007-10-8 songxw Initial creation.
|
******************************************************************************/
|
|
#if !defined(__TCP_TRANSPORT_H__)
|
#define __TCP_TRANSPORT_H__
|
|
using namespace std;
|
|
#include <time.h>
|
#include <netinet/in.h>
|
#include "TypeDef.h"
|
#include "str.h"
|
|
|
typedef enum
|
{
|
TCP_CLIENT,
|
TCP_SERVER
|
}TcpServiceType_E;
|
|
#define TPKT_MAX_LEN 4
|
#define RTSP_PACKET_LEN_WITHOUT_BODY 1024
|
#define STREAM_BUFFER_MAX_LEN (1024 * 100)
|
#define TCP_STREAM_BUFFER_MAX_LEN (1024 * 50)
|
|
/* TCP transport class for create and destroy TCP socket programme, receive and send TCP packet */
|
class CTcpTransport
|
{
|
public:
|
CTcpTransport();
|
CTcpTransport(char *pIpAddr, UINT16 port);
|
virtual ~CTcpTransport();
|
int Create(TcpServiceType_E eType = TCP_CLIENT, char *pAddr = NULL, UINT16 port = 0);
|
int Listen(void);
|
bool ReadSelect(UINT32 timeout);
|
bool IsReadSelect(UINT32 timeout);
|
int Connect(void);
|
int Send(UINT8 *pBuf, int len);
|
int Read(UINT8 *pBuf, int BufLen, int param = 0);
|
int ServerRead(UINT8 *pBuf, int BufLen, int param = 0);
|
int Close(void);
|
|
int GetSockName(char *pIpAddr, UINT16 &port);
|
|
int SetTcpClientSrcInfo(const char *pIpAddr, UINT16 port)
|
{
|
if((pIpAddr!= NULL) && (strlen(pIpAddr) > 0) && (port>0))
|
{
|
strncpy2(sTcpClientIpAddr, pIpAddr, 32);
|
uTcpClientPort = port;
|
return 0;
|
}
|
return -1;
|
}
|
public:
|
TcpServiceType_E sType;
|
int SockFd;
|
|
//remote ip address and port
|
char sIpAddr[32+1];
|
UINT16 uPort;
|
|
//tcpclient srcip and srcport
|
//mrs ·¢ËÍÂëÁ÷µÄʱºò Òª¹Ì¶¨Ô´Port
|
char sTcpClientIpAddr[32+1];
|
UINT16 uTcpClientPort;
|
};
|
|
#endif //#if !defined(__TCP_TRANSPORT_H__)
|