Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CAsyncSocket Client not connecting. Plz Help.

Status
Not open for further replies.

bnhshallow

Programmer
Dec 14, 2001
12
US
I am trying to make a connection between a client and server. Both are running on my machine and I am using loopback, but for some reason the client wont connect.

Here is my code for the client:
Code:
void CSocketsDlg::OnOK() 
{
	CString IpName;
	GetDlgItem(IDC_IP) -> SetWindowText(IpName);

if(m_sMySocket.Create())
{}
else
{MessageBox("Socket Failed");}

if(m_sMySocket.Connect(IpName, 4000))
{GetDlgItem(IDC_STAT) -> SetWindowText("Connection Made Successfully");}
else
{GetDlgItem(IDC_STAT) -> SetWindowText("Connection Failed");}
m_sMySocket.Close(); 
}

When I try to connect to the server, I get the "Connection Failed" error message.



Here is my server code just incase you need it:
Code:
void CServerDlg::OnOK() 
{
m_sMySocket.Create(4000);

if(m_sMySocket.Listen())
{GetDlgItem(IDC_STAT) -> SetWindowText("Listen Command Successful");}
else
{GetDlgItem(IDC_STAT) -> SetWindowText("Listen Failed");}
}

void CServerDlg::OnAccept()
{
if(m_sMySocket.Accept(m_sMySocket2))
{GetDlgItem(IDC_STAT) -> SetWindowText("Accept Successful");
MessageBox("Connection Made!");}
else
{GetDlgItem(IDC_STAT) -> SetWindowText("Accept Failed");}
}

I have tried sevral different things and havn't been able to connect. Can anyone tell me what I am doing wrong?

Thanks,
BNHShallow
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top