Click here to Skip to main content
15,888,802 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CRegKey read from registry? Pin
Richard MacCutchan25-Sep-13 22:45
mveRichard MacCutchan25-Sep-13 22:45 
GeneralRe: CRegKey read from registry? Pin
bosfan26-Sep-13 20:42
bosfan26-Sep-13 20:42 
GeneralRe: CRegKey read from registry? Pin
Richard MacCutchan26-Sep-13 21:30
mveRichard MacCutchan26-Sep-13 21:30 
QuestionSocket Communication - Server with 2 different clients Pin
manoharbalu25-Sep-13 0:47
manoharbalu25-Sep-13 0:47 
AnswerRe: Socket Communication - Server with 2 different clients Pin
Richard MacCutchan25-Sep-13 1:01
mveRichard MacCutchan25-Sep-13 1:01 
GeneralRe: Socket Communication - Server with 2 different clients Pin
manoharbalu25-Sep-13 2:24
manoharbalu25-Sep-13 2:24 
GeneralRe: Socket Communication - Server with 2 different clients Pin
Richard MacCutchan25-Sep-13 2:59
mveRichard MacCutchan25-Sep-13 2:59 
GeneralRe: Socket Communication - Server with 2 different clients Pin
manoharbalu25-Sep-13 19:12
manoharbalu25-Sep-13 19:12 
This is my sample code
I have created 2 Socket objects derived from CListenSocket which in turn is derived from CSocket. The 2 sockets listen in 2 different ports as you said. When a client request comes in the CListenSocket, the AcceptClients() in the CMainframe is called. A Client socket pSocket is created. The new client is accepted in which ever port the client tries to connect. In the below eg. the client tries to connect in port no 1500.
But when I debug the code in the function CMainFrame::AcceptClients(), it gets inside the condition
if (m_pSocket->Accept())
and gets lost. whereas it is supposed to get inside the condition
if (m_pSVRLisnSocket->Accept(*pSocket))

Anyone, Please clarify this and suggest me a method to find out a way to distinguish the connection from 2 different ports 1499 and 1500.

Server side code
BOOL CMainFrame::StartServer()
{
PortNo = 1499;
if(!m_pSocket)
{
m_pSocket = new CListenSocket(this);
if ( m_pSocket->Create(PortNo) )
m_pSocket->Listen();
else
AfxMessageBox("Socket creation failed. Failed to communicate with operator station");
}
PortNo = 1500;
if(!m_pSVRLisnSocket) //CListenSocket* m_pSVRLisnSocket
{
m_pSVRLisnSocket = new CListenSocket(this);
if( m_pSVRLisnSocket->Create(PortNo) ) //sandeep1
m_pSVRLisnSocket->Listen();
else
AfxMessageBox("Socket creation failed. Failed to communicate with operator station");
}
}

//Server Listen Socket class
void CListenSocket::OnAccept(int nErrorCode)
{
// TODO: Add your specialized code here and/or call the base class
CSocket::OnAccept(nErrorCode);
m_pFrm->AcceptClients(); //CMainFrame* m_pFrm;
}
void CMainFrame::AcceptClients()
{
COprSocket* pSocket = new COprSocket(this,cId);
if (m_pSocket->Accept(*pSocket)) //CListenSocket* m_pSocket
{
CString curOpr;
UINT i;
pSocket->GetPeerName(curOpr,i);
SendPrelimData(pSocket);
}
else
delete pSocket;
/////////////////////////////////////////////////////////////////////////////////////
if (m_pSVRLisnSocket->Accept(*pSocket)) //CListenSocket* m_pSVRLisnSocket
{
CString sCltIP;
UINT iPort;
pSocket->GetPeerName(sCltIP,iPort);
if (iPort == 1500)
{
AfxMessageBox("INS CLT connected.");
}
}
else
delete pSocket;

/////////////////////////////////////////////////////////////////////////////////////
}


Client Side code
BOOL CMainFrame::ConnectSocket(LPCTSTR lpszAddress, UINT nPort)
{
m_pCLTSocket = new COprSocket(this); //COprSocket *m_pCLTSocket
if (!m_pCLTSocket->Create())
{
delete m_pCLTSocket;
m_pCLTSocket = NULL;
return FALSE;
}
if(!m_pCLTSocket->Connect(lpszAddress, 1500))
{
delete m_pCLTSocket;
m_pCLTSocket = NULL;
return FALSE;
}
}
GeneralRe: Socket Communication - Server with 2 different clients Pin
Richard MacCutchan25-Sep-13 21:28
mveRichard MacCutchan25-Sep-13 21:28 
GeneralRe: Socket Communication - Server with 2 different clients Pin
manoharbalu25-Sep-13 22:11
manoharbalu25-Sep-13 22:11 
GeneralRe: Socket Communication - Server with 2 different clients Pin
Richard MacCutchan25-Sep-13 22:21
mveRichard MacCutchan25-Sep-13 22:21 
GeneralRe: Socket Communication - Server with 2 different clients Pin
manoharbalu26-Sep-13 3:36
manoharbalu26-Sep-13 3:36 
GeneralRe: Socket Communication - Server with 2 different clients Pin
Richard MacCutchan26-Sep-13 4:20
mveRichard MacCutchan26-Sep-13 4:20 
GeneralRe: Socket Communication - Server with 2 different clients Pin
koll Zhu25-Sep-13 16:17
koll Zhu25-Sep-13 16:17 
AnswerRe: Socket Communication - Server with 2 different clients Pin
Richard MacCutchan25-Sep-13 21:17
mveRichard MacCutchan25-Sep-13 21:17 
AnswerRe: Socket Communication - Server with 2 different clients Pin
Malli_S25-Sep-13 2:24
Malli_S25-Sep-13 2:24 
QuestionClarification regarding the function CAsyncSocket::GetPeerName() Pin
manoharbalu25-Sep-13 0:14
manoharbalu25-Sep-13 0:14 
AnswerRe: Clarification regarding the function CAsyncSocket::GetPeerName() Pin
Richard MacCutchan25-Sep-13 0:22
mveRichard MacCutchan25-Sep-13 0:22 
GeneralRe: Clarification regarding the function CAsyncSocket::GetPeerName() Pin
manoharbalu25-Sep-13 0:48
manoharbalu25-Sep-13 0:48 
Questionset the version Pin
koll Zhu24-Sep-13 23:29
koll Zhu24-Sep-13 23:29 
AnswerRe: set the version Pin
Richard MacCutchan25-Sep-13 0:23
mveRichard MacCutchan25-Sep-13 0:23 
GeneralRe: set the version Pin
koll Zhu25-Sep-13 0:46
koll Zhu25-Sep-13 0:46 
GeneralRe: set the version Pin
koll Zhu25-Sep-13 0:51
koll Zhu25-Sep-13 0:51 
QuestionRe: set the version Pin
Maximilien25-Sep-13 8:03
Maximilien25-Sep-13 8:03 
AnswerRe: set the version Pin
koll Zhu25-Sep-13 16:06
koll Zhu25-Sep-13 16:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.