C++ Programming
05-05-2009, 01:40 PM
I made one simple client server program.
Server Socket created without any error but client program returns WSAECONNREFUSED error.
For one confirmation i create another one server socket with same port at that time it's not gives any error.
I get confused because it creates two sockets for same port without any error. But this also client gives same error
please help me to get out from this issue.
Server:
m_pserversock = new CServerSocket(this);
bsucessflag= m_pserversock->Create(m_portno,SOCK_STREAM,NULL);
status=m_pserversock->GetLastError();
if(bsucessflag)
{
// TODO: Server Listen
bsucessflag= m_pserversock->Listen(5);
if(bsucessflag)
{
//CString Stemp = m_display.GetWindowText(Stemp,m_display.get
m_display.SetWindowText("Server Listening\r\n");
}
else
{
m_display.SetWindowText("Unable to Listen\r\n");
OnDisconnect();
}
int a=m_pserversock->m_hSocket;
}
else AfxMessageBox("Unable to Create");
CSocket *temp;
temp = new CSocket;
bsucessflag=temp->Create(m_portno+1,SOCK_STREAM,NULL);
if(!bsucessflag)
AfxMessageBox("Error");
CServerSocket,CClientsock is from CSocket.
Client:
m_pClientsock = new CClientsock(this);
if(m_pClientsock->Create())
{
if(m_pClientsock->Connect(dlg.m_Servername,dlg.m_Portno))
{
AfxMessageBox("Connected to Server");
Init();
m_bIsConnect = TRUE;
m_Username = dlg.m_Username;
}
else
{
int istatus=m_pClientsock->GetLastError();
AfxMessageBox("Not able to Connect Server");
delete m_pClientsock;
m_pClientsock = NULL;
}
}
else
AfxMessageBox("Not able to Create");
Server Socket created without any error but client program returns WSAECONNREFUSED error.
For one confirmation i create another one server socket with same port at that time it's not gives any error.
I get confused because it creates two sockets for same port without any error. But this also client gives same error
please help me to get out from this issue.
Server:
m_pserversock = new CServerSocket(this);
bsucessflag= m_pserversock->Create(m_portno,SOCK_STREAM,NULL);
status=m_pserversock->GetLastError();
if(bsucessflag)
{
// TODO: Server Listen
bsucessflag= m_pserversock->Listen(5);
if(bsucessflag)
{
//CString Stemp = m_display.GetWindowText(Stemp,m_display.get
m_display.SetWindowText("Server Listening\r\n");
}
else
{
m_display.SetWindowText("Unable to Listen\r\n");
OnDisconnect();
}
int a=m_pserversock->m_hSocket;
}
else AfxMessageBox("Unable to Create");
CSocket *temp;
temp = new CSocket;
bsucessflag=temp->Create(m_portno+1,SOCK_STREAM,NULL);
if(!bsucessflag)
AfxMessageBox("Error");
CServerSocket,CClientsock is from CSocket.
Client:
m_pClientsock = new CClientsock(this);
if(m_pClientsock->Create())
{
if(m_pClientsock->Connect(dlg.m_Servername,dlg.m_Portno))
{
AfxMessageBox("Connected to Server");
Init();
m_bIsConnect = TRUE;
m_Username = dlg.m_Username;
}
else
{
int istatus=m_pClientsock->GetLastError();
AfxMessageBox("Not able to Connect Server");
delete m_pClientsock;
m_pClientsock = NULL;
}
}
else
AfxMessageBox("Not able to Create");