I have been using winsock for awhile now, mainly connecting to webservers. I recently coded a program to connect to my other computer on the network. I'm behind a router, and the port is forwarded. my program worked fine untill I added extra code (another thread and connection) whichh I then commented out entirely.
when the server program reaches the accept line, it waits (no errors) when my other program tries to connect it fails with errir 10060 "A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. " windows firewall is off on both and have tried turning my firewall off on both. No luck.
The odd thing is, if the server + client both run on either computer and connect via 127.0.0.1 or 192.168.1.3 it works fine, no problems at all.
heres my c++ code
server
WSADATA info;
if (WSAStartup(0x101,&info) != 0)
{
MessageBox(NULL,"ERROR 1","ERROR",MB_OK);
return false;
}
soc = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if (soc == INVALID_SOCKET)
{
MessageBox(NULL,"ERROR 2","ERROR",MB_OK);
return false;
}
struct sockaddr_in sa;
sa.sin_addr.s_addr = INADDR_ANY;
sa.sin_family = AF_INET;
sa.sin_port = htons(1447);
if (bind(soc,(SOCKADDR*)&sa,sizeof(sa)) == SOCKET_ERROR)
{
MessageBox(NULL,"ERROR 3","ERROR",MB_OK);
closesocket(soc);
return false;
}
MessageBox(NULL,"binded","ERROR",MB_OK);
if (listen(soc,1) == SOCKET_ERROR)
{
MessageBox(NULL,"ERROR 4","ERROR",MB_OK);
closesocket(soc);
return false;
}
MessageBox(NULL,"listening","ERROR",MB_OK);
do
{
clientSoc = accept(soc,NULL,NULL);
if (clientSoc == INVALID_SOCKET)
{
int i = WSAGetLastError();
}
}
while(clientSoc == INVALID_SOCKET);
and client
WSADATA info;
if (WSAStartup(0x101,&info) != 0)
{
MessageBox(NULL,"Error setting up winsock","ERROR",MB_OK|MB_ICONSTOP);
return false;
}
soc = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if (soc == INVALID_SOCKET)
{
MessageBox(NULL,"Error creating socket","ERROR",MB_OK|MB_ICONSTOP);
return false;
}
struct hostent *hp;
struct sockaddr_in sa;
unsigned int addr = inet_addr(IP);
hp = gethostbyaddr((char*)&addr,sizeof(addr),AF_INET);
if (hp == NULL)
{
MessageBox(NULL,"Error getting host","ERROR",MB_OK|MB_ICONSTOP);
closesocket(soc);
return false;
}
sa.sin_addr.s_addr = *((unsigned long*)hp->h_addr);
sa.sin_family = AF_INET;
sa.sin_port = htons(1447);
if (connect(soc,(struct sockaddr*)&sa,sizeof(sa)))
{
int i = WSAGetLastError();
MessageBox(NULL,"Error connecting to server","ERROR",MB_OK|MB_ICONSTOP);
closesocket(soc);
return false;
}
IP is a 15 element char array memset to 0 first
any help would be appreciated.
www.stickskate.com -> check it out, some gnarly stick skating movies