cserveradmin.cpp

来自「陆其明的实务精选中附带光盘中的视频聊天源代码」· C++ 代码 · 共 91 行

CPP
91
字号
//
// CServerAdmin.cpp
//

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

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

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

/////////////////////////////////////////////////////////////////////////
CServerAdmin::CServerAdmin()
{
	mLocalUDPPort  = SERVER_UDP_PORT;
	mTargetUDPPort = CLIENT_UDP_PORT;
}

CServerAdmin::~CServerAdmin()
{
}

SOCKET CServerAdmin::GetVideoStreamSocket(void)
{
	return mVideoStream.GetSocket();
}

SOCKET CServerAdmin::GetAudioStreamSocket(void)
{
	return mAudioStream.GetSocket();
}

bool CServerAdmin::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_ClientCalling:
				// Retrieve the client IP first
				SetTargetIP(ntohl(inet_addr((char*)ioParam2)));
				// Send local device config to the peer
				SendLocalDeviceConfigToPeer();
				break;

			case cmd_DeviceConfig:
				// Save the remote device config
				SetDeviceConfig(pCmd->param1 << 2);
				// Begin to create TCP connection
				mVideoStream.ConnectTo(mTargetIP, CLIENT_TCP_PORT);
				mAudioStream.ConnectTo(mTargetIP, CLIENT_TCP_PORT);
				break;

			case cmd_BuildFilterGraph:
				{
					// Now the server begins to build filter graph
					BOOL isBuilding = TRUE;
					Broadcast(msg_ModifyFilterGraph, &isBuilding);
				}
				break;

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

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

⌨️ 快捷键说明

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