Click here to Skip to main content
15,896,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
void CSocketClientDlg::OnBnClickedSendmsg()
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(m_sSendMsg.GetLength() == 0)
	{
	    MessageBox("Type your Message !");
		return;
	}
	CString sStr = ":";
	
	CString sUserName = m_sUserNmae +sStr+ m_sSendMsg;
	m_pClientSocketSever->Send(sUserName,sUserName.GetLength());
	m_SentList.InsertItem(0,sUserName);

	CString sTime = CTime::GetCurrentTime().Format("%H:%M:%S");
	m_SentList.SetItemText(0,1,sTime);

	m_nCounter = m_SentList.GetItemCount();
	m_DeleteItems = m_nCounter;
	m_nCounter++;
	m_sSendMsg =" ";
	UpdateData(FALSE);

//Server
C#
void CServerSocketDlg::Reciever(char chData[100])
{
	m_list.InsertItem(0, chData);
	CString sTime = CTime::GetCurrentTime().Format("%H:%M:%S");

	m_list.SetItemText(0,1,sTime);
	m_nCounter = m_list.GetItemCount();

	m_nNumOfMsg = m_nCounter;
	m_sSendMsg = chData;
	m_nCounter++;
	UpdateData(FALSE);
}

void CServerSocketDlg::OnBnClickedSendmsg()
{
	UpdateData(1);
	if(m_sSendMsg.GetLength() == 0)
	{
	    MessageBox("Type your Message !");
		return;
	}
	
	CString sStr = "  :";
	CString sUserName = m_sUserName +sStr+ m_sSendMsg;
	m_pServer->SendMessage(sUserName);
	
	m_SentList.InsertItem(0, sUserName);
	CString sTime = CTime::GetCurrentTime().Format("%H:%M:%S");
   
	m_SentList.SetItemText(0,1,sTime);
	m_nCounter = m_SentList.GetItemCount();
	
	m_nSentMsgNum = m_nCounter;
	m_nCounter++;
	m_sSendMsg = " ";

	UpdateData(0);

	
}


What I have tried:

please tell i made server and client using socket programming MFC
Posted
Updated 30-May-16 2:23am

1 solution

The server needs to build a table containing the client IP addresses. Then when a client sends a message, the server passes it on to every client in the table.
 
Share this answer
 
Comments
Haris1228 31-May-16 1:51am    
the port and ip address of client is same
Richard MacCutchan 31-May-16 2:54am    
Same as what?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900