Multicast.cpp ( File view )

  • By nwpurain 2014-10-21
  • View(s):717
  • Download(s):20
  • Point(s): 3
			// Multicast.cpp : implementation file
//

#include "stdafx.h"
#include "NetAssist.h"
#include "Multicast.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMulticast dialog


CMulticast::CMulticast(CWnd* pParent /*=NULL*/)
	: CDialog(CMulticast::IDD, pParent)
{

	//{
{
AFX_DATA_INIT(CMulticast)
		// NOTE: the ClassWizard will add member initialization here

	m_ChatMessage = _T("");
	m_ChatWindow = _T("");
	m_strIP = _T("");
	m_Loopback = FALSE;
	m_nPort = 0;
	m_nTTL = 0;
	m_nDuplication = 1;
	//
}
}AFX_DATA_INIT

}


void CMulticast::DoDataExchange(CDataExchange* pDX)
{

	CDialog::DoDataExchange(pDX);
	//{
{
AFX_DATA_MAP(CMulticast)
		// NOTE: the ClassWizard will add DDX and DDV calls here

	DDX_Control(pDX, IDC_IPADDRESS, m_ctrIPAddress);
	DDX_Control(pDX, IDC_CHATWINDOW, m_ctrChatWindow);
	DDX_Control(pDX, IDC_LOCAL_ADDRESS, m_ctrLocalAddress);
	DDX_Control(pDX, IDC_DUPLICATION, m_ctrDuplication);
	DDX_Control(pDX, IDC_NOTIFICATION, m_ctrNotification);
	DDX_Control(pDX, IDSEND, m_ctrSend);
	DDX_Control(pDX, IDC_CHATMESSAGE, m_ctrChatMessage);
	DDX_Control(pDX, IDC_TTL, m_ctrTTL);
	DDX_Control(pDX, IDC_PORT, m_ctrPort);
	DDX_Control(pDX, IDC_LOOPBACK, m_ctrLoopBack);
	DDX_Control(pDX, IDC_LEAVE, m_ctrLeave);
	DDX_Control(pDX, IDC_JOIN, m_ctrJoin);
	DDX_Text(pDX, IDC_CHATMESSAGE, m_ChatMessage);
	DDV_MaxChars(pDX, m_ChatMessage, 512);
	DDX_Text(pDX, IDC_CHATWINDOW, m_ChatWindow);
	DDX_Text(pDX, IDC_IPADDRESS, m_strIP);
	DDX_Check(pDX, IDC_LOOPBACK, m_Loopback);
	DDX_Text(pDX, IDC_PORT, m_nPort);
	DDX_Text(pDX, IDC_TTL, m_nTTL);
	DDX_Text(pDX, IDC_DUPLICATION, m_nDuplication);
	DDV_MinMaxUInt(pDX, m_nDuplication, 1, 50);
	//
}
}AFX_DATA_MAP

}


BEGIN_MESSAGE_MAP(CMulticast, CDialog)
	//{
{
AFX_MSG_MAP(CMulticast)
	ON_BN_CLICKED(IDC_JOIN, OnJoin)
	ON_BN_CLICKED(IDSEND, OnSend)
	ON_BN_CLICKED(IDC_LEAVE, OnLeave)
	ON_BN_CLICKED(IDC_CLEAR_MESSAGE, OnClearMessage)
	ON_WM_TIMER()
	//
}
}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMulticast message handlers

BOOL CMulticast::OnInitDialog()
{

	CDialog::OnInitDialog();
	
	// Add "About..." menu item to system menu.
	
	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{

		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{

			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		
}
	
}
	
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	SetTimer(1, 100, NULL);	/* Timer to poll and check for any arriving messages */
	m_ctrIPAddress.SetWindowText("224.0.0.99");
	m_ctrPort.SetWindowText("1024");
	m_ctrTTL.SetWindowText("1");
	UpdateData(TRUE);
	m_Socket.SetCallBack(this);
	m_nDuplication=1; UpdateData(FALSE);
	return TRUE;  // return TRUE  unless you set the focus to a control

}


void CMulticast::VirtualTimer()
{

	if(m_Socket.bDataReceived)		/* If a message has arrived */
	{

		CString strTemp;
		strTemp=m_Socket.m_strBuffer;
		if(strTemp=="Clear"){

			m_ctrChatWindow.SetWindowText("");
			m_ctrNotification.SetWindowText("[Clear] detected.");
			m_ChatWindow="";
		
}
		else
		{

			strTemp.Format("From[%s:%d]:%s\r\n%s", (char*)(LPCTSTR)m_Socket.m_strSendersIP, m_Socket.m_nSendersPort, (char*)(LPCTSTR)m_Socket.m_strBuffer, (char*)(LPCTSTR)m_ChatWindow);
			m_ChatWindow = strTemp;
			m_ctrChatWindow.SetWindowText(strTemp);
			m_Socket.bDataReceived = FALSE;
			//UpdateData(FALSE);
		
}
	
}

}

void CMulticast::OnJoin() 
{

	// TODO: Add your control notification handler code here
	//	if (m_JoinDlg.DoModal()	== IDOK)
	//	{

	//		if(!m_Socket.JoinGroup(m_JoinDlg.m_IP, m_JoinDlg.m_nPort, m_JoinDlg.m_nTTL, m_JoinDlg.m_Loopback))
	//			AfxMessageBox("Error joining host group");
	//	
}
	m_ctrLoopBack;
	UpdateData(TRUE);
#ifndef ErrorText
#define ErrorText(buffer) FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | \
	FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
	NULL, GetLastError(), \
	MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \
	(LPTSTR) &buffer, 0, NULL );
#endif
	CString strTemp;
	unsigned int IP_A;
	UpdateData(TRUE);
	strTemp=m_strIP.Mid(0, m_strIP.Find('.',0));
	IP_A=atoi(strTemp);
	if(IP_A<224 || IP_A>239 || m_nPort>65536)
	{

		m_ChatWindow+="地址范围:224.0.0.0~239.255.255.254,端口号范围:0~65535\r\n";
		UpdateData(FALSE);
		m_ctrNotification.SetWindowText("Current configuration not OK. Please check it out.");
		m_ctrSend.EnableWindow(FALSE);
		return;
	
}
	else
	{

		if(!m_Socket.JoinGroup(m_strIP, m_nPort, m_nTTL, m_Loopback))
		{

			//		AfxMessageBox("Error joining host grou
...
...
(Please download the complete source code to view)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 3

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
AcceptSocket.cpp899.00 B14-04-12|15:31
AcceptSocket.h1.24 kB15-06-14|22:31
Broadcast.cpp5.17 kB16-06-14|22:24
Broadcast.h1.45 kB16-06-14|22:24
ConnectSocket.cpp871.00 B14-04-12|15:26
ConnectSocket.h1.31 kB15-06-14|22:31
AcceptSocket.obj5.96 kB16-06-14|21:40
Broadcast.obj23.60 kB16-06-14|22:24
ConnectSocket.obj6.00 kB16-06-14|21:40
ListenSocket.obj7.41 kB16-06-14|21:40
Multicast.obj35.04 kB16-06-14|21:40
MulticastSocket.obj20.98 kB16-06-14|21:40
NetAssist.exe2.11 MB16-06-14|23:06
NetAssist.ilk2.48 MB16-06-14|23:06
NetAssist.obj12.44 kB16-06-14|22:29
NetAssist.pch5.27 MB16-06-14|21:40
NetAssist.pdb4.05 MB16-06-14|23:06
NetAssist.res10.88 kB16-06-14|22:29
NetAssistDlg.obj30.00 kB16-06-14|22:29
StdAfx.obj103.86 kB16-06-14|21:40
TCP.obj25.63 kB16-06-14|22:57
Unicast.obj22.99 kB16-06-14|23:06
vc60.idb233.00 kB15-10-14|23:04
vc60.pdb364.00 kB16-06-14|23:06
复件0.00 B17%|16-06-14
ListenSocket.cpp1.13 kB14-04-12|15:31
ListenSocket.h1.27 kB15-06-14|22:31
Multicast.cpp7.64 kB16-06-14|00:07
Multicast.h1.96 kB16-06-14|00:09
MulticastSocket.cpp6.81 kB16-06-14|00:00
MulticastSocket.h2.33 kB10-06-14|19:54
NetAssist.aps40.26 kB16-06-14|22:29
NetAssist.clw4.55 kB15-10-14|23:19
NetAssist.cpp2.15 kB15-06-14|22:26
NetAssist.dsp4.91 kB16-06-14|21:12
NetAssist.dsw541.00 B15-06-14|22:26
NetAssist.h1.33 kB15-06-14|22:26
NetAssist.ncb113.00 kB16-10-14|00:11
NetAssist.opt58.50 kB16-10-14|00:11
NetAssist.plg869.00 B16-06-14|23:06
NetAssist.rc10.41 kB16-06-14|22:29
NetAssistDlg.cpp5.98 kB16-06-14|22:29
NetAssistDlg.h1.63 kB16-06-14|22:29
ReadMe.txt3.55 kB15-06-14|22:26
NetAssist.ico1.05 kB15-06-14|22:26
NetAssist.rc2401.00 B15-06-14|22:26
resource.h3.09 kB16-06-14|22:29
StdAfx.cpp211.00 B15-06-14|22:26
StdAfx.h1.08 kB15-06-14|22:26
TCP.cpp5.92 kB16-06-14|21:09
TCP.h1.54 kB15-06-14|23:32
Unicast.cpp5.00 kB16-06-14|23:06
Unicast.h1.49 kB16-06-14|21:01
Debug0.00 B16-06-14|23:06
res0.00 B15-06-14|22:26
NetAssist06160.00 B16-10-14|00:11
...
Sponsored links

Multicast.cpp (3.87 MB)

Need 3 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D