⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cclientadmin.cpp

📁 陆其明的实务精选中附带光盘中的视频聊天源代码
💻 CPP
字号:
//
// CClientAdmin.cpp
//

/*-----------------------------------------------------*\
			HQ Tech, Make Technology Easy!       
 More information, please go to http://hqtech.nease.net.
/*-----------------------------------------------------*/

#include "stdafx.h"
#include <streams.h>
#include "CClientAdmin.h"
#include "GlobalDefs.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////
CClientAdmin::CClientAdmin()
{
	mLocalUDPPort  = CLIENT_UDP_PORT;
	mTargetUDPPort = SERVER_UDP_PORT;

	// Receive message from TCP Listener
	mTcpListener.AddMsgReceiver(this);
}

CClientAdmin::~CClientAdmin()
{
	Uninit();
}

BOOL CClientAdmin::Init(void)
{
	BOOL pass = CRoleAdmin::Init();

	// Start TCP listening on the client
	if (pass)
	{
		mTcpListener.SetListenPort(CLIENT_TCP_PORT);
		pass = mTcpListener.Create();
	}
	if (pass)
	{
		pass = mTcpListener.StartListening();
	}
	return pass;
}

void CClientAdmin::Uninit(void)
{
	mTcpListener.StopListening();

	CRoleAdmin::Uninit();
}

BOOL CClientAdmin::CallServer(void)
{
	return SendSimpleCommand(cmd_ClientCalling);
}

SOCKET CClientAdmin::GetVideoStreamSocket(void)
{
	return mTcpListener.GetAccepted(0);
}

SOCKET CClientAdmin::GetAudioStreamSocket(void)
{
	return mTcpListener.GetAccepted(1);
}

bool CClientAdmin::ReceiveMessage(MessageT inMessage, 
								  void * ioParam, 
								  void * ioParam2)
{
	switch (inMessage)
	{
	case msg_UDPCommandReceived:
		{
			UDP_Pack * pCmd = (UDP_Pack*) ioParam;
			pCmd->my_ntoh();
			// Process different commands
			switch (pCmd->command)
			{
			case cmd_DeviceConfig:
				// Save the remote device config
				SetDeviceConfig(pCmd->param1 << 2);
				// Send local device config to the peer
				SendLocalDeviceConfigToPeer();
				break;

			case cmd_DisconnectRequest:
				{
					BOOL isBuilding = FALSE;
					Broadcast(msg_ModifyFilterGraph, &isBuilding);
				}
				break;
			}
		}
		return true;

	case msg_TCPSocketAccepted:
		if (mTcpListener.IsSocketReady())
		{
			// Make the server begin to build filter graph
			SendSimpleCommand(cmd_BuildFilterGraph);
			// Now the client must begin to build filter graph too
			BOOL isBuilding = TRUE;
			Broadcast(msg_ModifyFilterGraph, &isBuilding);
		}
		return true;
	}

	return CRoleAdmin::ReceiveMessage(inMessage, ioParam, ioParam2);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -