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