www.pudn.com > AVChat1.rar > CServerAdmin.cpp


// 
// CServerAdmin.cpp 
// 
 
/*-----------------------------------------------------*\ 
			HQ Tech, Make Technology Easy!        
 More information, please go to http://hqtech.nease.net. 
/*-----------------------------------------------------*/ 
 
#include "stdafx.h" 
#include  
#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); 
}