live555学习之一RTSPServer的创建监听并监听客户端

来源:互联网 发布:行知实验小学怎么样 编辑:程序博客网 时间:2024/06/10 07:18



服务器创建一个socket作为server端的套接字

1.RTSPServer::setUpOurSocket



1.1.调用 GroupsockHelper 的 setupStreamSocket创建一个socket连接,并绑定,

ourSocket = setupStreamSocket(env, ourPort);


1.2. 设置发送缓冲区为50K

if (!increaseSendBufferTo(env, ourSocket, 50*1024))


1.3. 监听端口 其最大连接数为LISTEN_BACKLOG_SIZE 20

    if (listen(ourSocket, LISTEN_BACKLOG_SIZE) < 0)


1.4. 返回创建的socket

return ourSocket;


调用构造函数
2.new RTSPServer



      2.1. 记录成员信息 端口号 记录socket

    fRTSPServerPort(ourPort), fRTSPServerSocket(ourSocket), fHTTPServerSocket(-1), fHTTPServerPort(0),    fServerMediaSessions(HashTable::create(STRING_HASH_KEYS)),    fClientConnections(HashTable::create(ONE_WORD_HASH_KEYS)),    fClientConnectionsForHTTPTunneling(NULL), // will get created if needed    fClientSessions(HashTable::create(STRING_HASH_KEYS)),    fPendingRegisterRequests(HashTable::create(ONE_WORD_HASH_KEYS)), fRegisterRequestCounter(0),    fAuthDB(authDatabase), fReclamationTestSeconds(reclamationTestSeconds),    fAllowStreamingRTPOverTCP(True) {  ignoreSigPipeOnSocket(ourSocket); // so that clients on the same host that are killed don't also kill us


2.2  注册一个成员函函数用于接收客户端的连接

void RTSPServer::incomingConnectionHandlerRTSP(void* instance, int /*mask*/) {  RTSPServer* server = (RTSPServer*)instance;  server->incomingConnectionHandlerRTSP1();}void RTSPServer::incomingConnectionHandlerRTSP1() {  incomingConnectionHandler(fRTSPServerSocket);}void RTSPServer::incomingConnectionHandler(int serverSocket) {


2.2.1accept返回客户端的socket描述符clientSocket

int clientSocket = accept(serverSocket, (struct sockaddr*)&clientAddr, &clientAddrLen);

2.2.2设置和客户端的连接模式为非阻塞的模式

makeSocketNonBlocking

2.2.3.设置客户端socket描述符的发送缓存为50*1024

increaseSendBufferTo(envir(), clientSocket, 50*1024);

2.2.4.创建一个处理连接函数

createNewClientConnection
RTSPClientConnection

2.2.4.1 将该链接添加进入fClientConnections的连接表中

fOurServer.fClientConnections->Add((char const*)this, this);

2.2.4.2 注册一个处理事件通信的函数(自己的程序可以用线程替代)

setBackgroundHandling(&incomingRequestHandler())



参考:
http://blog.csdn.net/cosmoslife/article/details/7565711
http://www.cnblogs.com/lidabo/p/4103509.html
原创粉丝点击