jrtplib3.11.1 TCP发送和接收视频流

参照tcptest.cpp

TCP客户端:       

       int   nClient = socket(AF_INET, SOCK_STREAM, 0);
        sockaddr_in   serverAddr;
        memset(&serverAddr, 0, sizeof(sockaddr_in));
        serverAddr.sin_family = AF_INET;
        serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
        serverAddr.sin_port = htons(10000);
        int  nRet = connect(nClient, (sockaddr*)&serverAddr, sizeof(serverAddr));
       
        int   status;
        int  nPackSize = 45678;
       RTPSessionParams   sessparams;
       sessparams.SetProbationType(RTPSources::NoProbation); 
       sessparams.SetOwnTimestampUnit(90000.0 / 25.0);
       sessparams.SetMaximumPacketSize(nPackSize+64); 

        m_pTrans = new RTPTCPTransmitter(NULL);//主要用成员变量,用于jrtplib库赋值
        status = m_pTrans->Init(true);
        status = m_pTrans->Create(65535, NULL);
        status = m_RTPSession.Create(sessparams, m_pTrans);
        checkerror(status);

        status = m_RTPSession.AddDestination(RTPTCPAddress(nClient));
        checkerror(status);

TCP服务器:

    int   nListener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (nListener == INVALID_SOCKET)
	{
		return  -1;
	}

	sockaddr_in   serverAddr;
	memset(&serverAddr, 0, sizeof(sockaddr_in));
	serverAddr.sin_family = AF_INET;
	serverAddr.sin_addr.S_un.S_addr = INADDR_ANY;
	serverAddr.sin_port = htons(10000);
	int  nRet = bind(nListener, (sockaddr*)&serverAddr, sizeof(serverAddr));
	if (nRet == SOCKET_ERROR)
	{
		return  -1;
	}
	if (listen(nListener, 1) == SOCKET_ERROR)
	{
		return  -1;
	}



		sockaddr_in   clientAddr;
		int  nLen = sizeof(sockaddr_in);
		int   nServer = -1;
		while (true)
		{
			nServer = accept(nListener, (sockaddr*)&clientAddr, &nLen);
			if (nServer == INVALID_SOCKET)
			{
				continue;
			}
			else
			{
				break;
			}
		}

		int  nPackSize = 45678;
		RTPSessionParams   sessparams;
		sessparams.SetProbationType(RTPSources::NoProbation);
		sessparams.SetOwnTimestampUnit(90000.0 / 25.0);
		sessparams.SetMaximumPacketSize(nPackSize + 64);

		pTransparams = new RTPTCPTransmitter(NULL);
		//RTPTCPTransmitter  transparams(NULL);
		status = pTransparams->Init(true);
		status = pTransparams->Create(65535, NULL);

		status = m_RTPTCPSession.Create(sessparams, pTransparams);
		if (status >= 0)
		{
			m_RTPTCPSession.AddDestination(RTPTCPAddress(nServer));
		}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值