簡單RTP傳送類c 實現

2021-09-22 22:14:59 字數 2643 閱讀 4253

我之前編譯了jrtplib 3.9.1,並且在專案中使用,結果發現在用這個庫時,程式體積有增加了300多k,感覺實在是有點笨重,我無法就是用來傳送rtp包而已。想想還是自己重新實現乙個簡單的類用用拉倒了,所以有了下面的**。

標頭檔案:

[cpp]view plain

copy

/*! 

@brief 簡單rtp庫 

@file easy_rtp.h 

*/  

#ifndef _easy_rtp_h  

#define _easy_rtp_h  

#include 

#include 

#ifdef _win32  

#include 

#else  

#include 

#include 

#include 

#include 

#include 

#ifndef invalid_socket  

#define invalid_socket  (socket)(~0)  

#endif  

#ifndef socket_error  

#define socket_error    (-1)  

#endif  

#ifndef closesocket  

#define closesocket(x)  close(x)  

#endif  

typedef int socket;  

#endif  

// 預設最大包大小(mtu 1500 - ip頭 20 - udp頭 8)  

#define default_max_packet_size 1472  

/*! 

@brief 簡單rtp資料報裝傳送庫 

*/  

class easyrtp  

rtpheader;  

// 最大包大小  

int16_t _maxpacketsize;  

// 傳送的緩衝  

char* _sbuf;  

// 序列號  

uint16_t _sn;  

// 時間戳  

uint32_t _ts;  

// 源標示  

uint32_t _ssrc;  

// 控制代碼  

socket _socket;  

// 目標位址  

struct sockaddr_in _destto;  

};  

#endif  // _easy_rtp_h  

cpp原始碼:

[cpp]view plain

copy

#include 

#include 

#include 

#include "easy_rtp.h"  

#include "byte_write.h"  

#include "utils.h"  

// 預設的rtp版本  

#define rtp_version         2  

// rtp頭大小  

#define rtp_header_size     12  

easyrtp::easyrtp( const std::string& destip, uint16_t port, uint16_t localport /*= 0*/, int16_t maxpacketsize /*= 1500*/ )  

:_maxpacketsize(maxpacketsize),  

_sbuf(null),  

_sn(utils::createrandam32()),  

_ts(utils::createrandam32()),  

_ssrc(utils::createrandam32())  

}  }  easyrtp::easyrtp( uint32_t destip, uint16_t port, uint16_t localport /*= 0*/, int16_t maxpacketsize /*= default_max_packet_size*/ )  

:_maxpacketsize(maxpacketsize),  

_sbuf(null),  

_sn(utils::createrandam32()),  

_ts(utils::createrandam32()),  

_ssrc(utils::createrandam32())  

}  }  easyrtp::~easyrtp()  

int32_t easyrtp::sendpacket( const char* buf, int32_t len, int8_t pt, bool mark, int32_t timestampinc )  

#endif  

return ret;  

}  

注:

stdint.h是新c++標準中的標頭檔案,定義了int32_t int8_t等typedef 型別。

C 郵件傳送 實現類

using system using system.collections.generic using system.configuration using system.io using system.linq using system.net.mail using system.net.mime...

C 的E mail傳送簡單實現

sendeeail.aspx page language c autoeventwireup true codefile sendeeail.aspx.cs inherits web test sendeeail sendeeail.aspx.cs using system using system...

實現TcpIp簡單傳送

private void timer1 tick object sender,eventargs e sr.close netstream.close tcpclient.close serverlistener.stop public void sendmeg string msg 傳送資訊 st...