Error 10060
- From: Nishchal Devnur <NishchalDevnur@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 27 Jun 2007 22:02:04 -0700
Hi,
I have two programs, one a server program and the other client. If i run
both the programs on the same machine evrything works fine, but if i run the
programs on two different machines then i get this error 10060, which is
connection timed out. am not able to fix the problem. pl help..
thank you.
btw the code snippets are:
server.cpp
#include "stdafx.h"
#include "server.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#include <iostream>
#include "afxsock.h"
#include "afx.h"
#include "winsock2.h"
#include "string.h"
#include "conio.h"
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
CSocket servsock,temp;
sockaddr_in sa;
WSADATA wsadata;
if (WSAStartup(2,&wsadata))
{
cout << "cant startup" ;
getch();
}
LPHOSTENT hp;
hp = gethostbyname("blrk0b3d");
if (hp == NULL)
{
int x;
x = GetLastError();
cout << x;
cout << "no such server";
getch();
}
sa.sin_addr = *((LPIN_ADDR)*hp->h_addr_list);
sa.sin_family = AF_INET;
sa.sin_port = htons (1000);
cout << hp->h_name << '\n';
cout << hp->h_addr_list;
if (!servsock.Create(1000,SOCK_STREAM,"127.0.0.1"))
{
cout << "cant create";
getch();
}
if (!servsock.Listen(5))
{
cout << "cant listen";
getch();
}
cout << "waiting for a connection";
if (!servsock.Accept(temp))
{
cout << "cant accept";
getch();
}
temp.Send("hi",2,0);
temp.Close();
getch();
}
return nRetCode;
}
and the client program is:
#include "stdafx.h"
#include "socket2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#include <iostream>
#include "afxsock.h"
#include "afx.h"
#include "winsock2.h"
#include "string.h"
#include "conio.h"
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
char recvbuffer[4] = "";
CSocket clientsock;
WSADATA wsadata;
//hostent * hp;
sockaddr_in sa;
if (WSAStartup(2,&wsadata))
{
cout << "cant startup" ;
getch();
}
//hp = gethostbyaddr(serv_addr,sizeof(serv_addr),AF_INET);
//hp = gethostbyname("blrk0b3d");
LPHOSTENT hp;
hp = gethostbyname("blrk0b3d"); // blrk0b3d id the computer name;
if (hp == NULL)
{
int x;
x = GetLastError();
cout << x;
cout << "no such server";
getch();
}
sa.sin_addr = *((LPIN_ADDR)*hp->h_addr_list);
sa.sin_family = AF_INET;
sa.sin_port = htons (1000);
cout << hp->h_name << '\n';
cout << hp->h_addr_list;
if (!clientsock.Create(0,SOCK_STREAM,"127.0.0.1"))
{
cout << "cant create";
getch();
}
if(!clientsock.Connect((sockaddr *)&sa,sizeof(sockaddr)))
{
cout << "cant connect";
int x;
x = GetLastError(); // here is the error.. which says connection timed out..
error :WSAETIMEDOUT
cout <<x;
getch();
}
clientsock.Receive(recvbuffer,4,0);
cout << recvbuffer;getch();
clientsock.ShutDown();
clientsock.Close();
// TODO: code your application's behavior here.
}
return nRetCode;
}
.
- Follow-Ups:
- Re: Error 10060
- From: Dave Lowther
- Re: Error 10060
- Prev by Date: RE: CAsyncSocket performing RST on Connect()
- Next by Date: Re: Error 10060
- Previous by thread: RE: CAsyncSocket performing RST on Connect()
- Next by thread: Re: Error 10060
- Index(es):
Relevant Pages
|
|