Click here to Skip to main content
Click here to Skip to main content

Multiple Client and Single Server in TCP and Broadcast

, 1 Nov 2007
Rate this:
Please Sign up or sign in to vote.
Multiple Client and Single Server in TCP and Broadcast
Screenshot - Message.jpg

Introduction

Description:-This Server will accept maximum 10 Client. Client sends message to server. Server will broadcast same message to connected all client expect who send. Here I am using word "broadcast" in TCP Stream. Generally broadcast is used in UDP stream.

If you want can changed in code to same message received by all clients

Enchantment:-if server want to send one Client you have developed own.

And special services server had option to send message to all connected client.

void CTestServerSocketDlg::OnDataReceived(WPARAM wParam,LPARAM lParam) 
{
 try
 {    
   CString csTemp; 
   int mnInstanceNo = (int)lParam; // client number who send data 
   CClientSocket  * pCheckSocket;  
   pCheckSocket = (CClientSocket *  ) m_ClientSocketArray.GetAt(mnInstanceNo); 
   
   char szBuff[1024]; 
   memset(szBuff,'\0',sizeof szBuff); 
   pCheckSocket->Receive(szBuff,1024);
   csTemp.Empty(); 
   csTemp.Format("%s",szBuff); 
   m_ctrlDataRec.InsertString(-1,csTemp); 
   UpdateData(false); 
   for ( int i=0;i<MAX_CONNECTION;i++) 
   {
    pCheckSocket = (CClientSocket * )m_ClientSocketArray.GetAt(i); 
    if(pCheckSocket) 
     {    if(pCheckSocket->m_nInstanceNo != mnInstanceNo) 
    {pCheckSocket->Send(szBuff,sizeof szBuff);}
      }
    }// end for
  }// end try
 catch(...) { }
Screenshot - server.jpg

License

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

Share

About the Author

sherton
Web Developer
India India
I am working at Hyderabad as vc++ software developer,I passed B.Com and B-level from DOEACC (www.doeacc.org.in)through O.U.Campus.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140826.1 | Last Updated 2 Nov 2007
Article Copyright 2007 by sherton
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid