live555客户端断网重连解决办法

live555自带的客户端例程testRTSPClient.c中不具备重连服务器的功能,通过对testRTSPClient.c改进可实现客户端以下功能:
1、连接器服务器失败后,可以定时重连服务器;
2、连接服务器成功后,网络异常,客户端可以重新连接服务器。

  //main
  while(1)
  {
	  eventLoopWatchVariable = 0;
	  // There are argc-1 URLs: argv[1] through argv[argc-1].  Open and start streaming each one:
	  for (int i = 1; i <= argc-1; ++i) {
		openURL(*env, argv[0], argv[i]);
	  }
	  // All subsequent activity takes place within the event loop:
	  env->taskScheduler().doEventLoop(&eventLoopWatchVariable);
		// This function call does not return, unless, at some point in time, "eventLoopWatchVariable" gets set to something non-zero.
	  Sleep(2000);
  }
  //void shutdownStream(RTSPClient* rtspClient, int exitCode) 
  if (--rtspClientCount == 0) {
    // The final stream has ended, so exit the application now.
    // (Of course, if you're embedding this code into your own application, you might want to comment this out,
    // and replace it with "eventLoopWatchVariable = 1;", so that we leave the LIVE555 event loop, and continue running "main()".)
    //exit(exitCode);
	eventLoopWatchVariable = 1;
  }

1、main函数添加一个死循环。
2、shutdownStream注释程序退出exit(exitCode),把eventLoopWatchVariable 设为1,因为当eventLoopWatchVariable 不为0时,env->taskScheduler().doEventLoop(&eventLoopWatchVariable)会退出,这样可以跳到main函数while的开始,重新请求服务器连接。

//void continueAfterPLAY(RTSPClient* rtspClient, int resultCode, char* resultString)
	scs.duration=30;
    // Set a timer to be handled at the end of the stream's expected duration (if the stream does not already signal its end
    // using a RTCP "BYE").  This is optional.  If, instead, you want to keep the stream active - e.g., so you can later
    // 'seek' back within it and do another RTSP "PLAY" - then you can omit this code.
    // (Alternatively, if you don't want to receive the entire stream, you could set this timer for some shorter value.)
    if (scs.duration > 0) {
      unsigned const delaySlop = 2; // number of seconds extra to delay, after the stream's expected duration.  (This is optional.)
      scs.duration += delaySlop;
      unsigned uSecsToDelay = (unsigned)(scs.duration*1000000);
      scs.streamTimerTask = env.taskScheduler().scheduleDelayedTask(uSecsToDelay, (TaskFunc*)streamTimerHandler, rtspClient);
    }

1、continueAfterPLAY函数里设置主循环超时时间,并注册超时处理函数:shutdownStream

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值